Hello All,
The following code will help you to make dynamic horizontal scroller. This means that on adding content or images the width of the container automatically increases using jquery.
If anyone wants to make horizontal scroller which is in between a page template, then we can use this scroller.
This will help anyone to make a scroller in between a page without disturbing the other element in the page.
In this we can add as many images as we want, the width of the scroller will take it automatically using jquery.
HTML:
<div class="image-gallery">
<ul class="image-list">
<li class="big-image">
<a href=""><img src="images/8067fb1cb9a711e385e9128e2849c1ef_8.jpg" alt=""/></a>
</li>
<div class="image-wrapper">
<li class="image-top">
<a href=""><img src="images/2a2dfa1ab61611e397e912139cd1d695_8.jpg" alt=""></a>
</li>
<li class="image-bottom">
<a href=""><img src="images/0d7827eeafbb11e399e212fd90a3f13f_8.jpg" alt=""></a>
</li>
</div>
<li class="big-image">
<a href=""><img src="images/3af7eddaa54811e385ff1234c61f9f0f_8.jpg" alt=""></a>
</li>
<div class="image-wrapper">
<li class="image-top">
<a href=""><img src="images/e0a94bc6a33a11e3a16a122b8b9af17f_8.jpg" alt=""></a>
</li>
<li class="image-bottom">
<a href=""><img src="images/e0a94bc6a33a11e3a16a122b8b9af17f_8.jpg" alt=""></a>
</li>
</div>
<li class="big-image">
<a href=""><img src="images/ebfe22e29ffe11e3bd500e5958617a65_8.jpg" alt=""></a>
</li>
<div class="image-wrapper">
<li class="image-top">
<a href=""><img src="images/844398e69f0c11e38c000e4efbc22637_8.jpg" alt=""></a>
</li>
<li class="image-bottom">
<a href=""><img src="images/d1d9aa8a975211e39a0512fb41973d49_8.jpg" alt=""></a>
</li>
</div>
</ul>
</div>
CSS:
.clr{
clear: both;
}
.image-gallery{
width:100%
}
.image-gallery li{
list-style: none;
float: left;
display: inline-block;
}
.image-gallery li.big-image img{
width: 400px;
}
.image-gallery .image-wrapper img{
width:197px;
}
.image-wrapper{
display: inline-block;
float: left;
margin: 0 0.5em;
width: 200px;
}
ul.image-list{
padding: 0.5em 0;
display: block;
}
ul li.image-top{
margin-bottom: 3px;
}
ul li.image-bottom{
margin-top: 3px;
}
JS:
$(document).ready(function(){
var list_count=0;
var div_count=0;
var list_width=0;
var div_width=0;
$('.image-list > li').each(function(){
list_width = $(this).width()+10;
list_count++;
})
$('.image-list > div').each(function(){
div_width = $(this).width()+10;
div_count++;
})
var total_width = (list_count * list_width) + (div_count * div_width);
console.log(total_width);
$('.image-list').css({"width":total_width})
})
0 Comment(s)