Reputation: 1699
I'm trying to find a way to make li
elements slides. I can make them all on one line (see my fiddle) and fit them in the ul
width. But when I click on a NEXT button I want them slide to the right to show the hidden li
.
My Fiddle: http://jsfiddle.net/5cmR7/
Smiliar Fiddle: http://jsfiddle.net/L5yEA/
EDIT: I want something like this but built in a better way, and more precise when clicking NEXT.
Upvotes: 4
Views: 336
Reputation: 206078
This is all you need:
var liN = $('ul.shop-groups li').length;
var galW = $('.content').width();
var curr = 0; // Set current 'li' slide
function animate(){
var setCurr= (curr===-1) ? (curr = liN-1) : (curr = curr%liN);
$('ul.shop-groups').stop().animate({left: -(galW*curr) },1200);
}
$('#prev, #next').click(function(){
var who= (this.id==='next') ? curr++ : curr-- ;
animate();
});
Just give an ID
to your buttons:
<input id="prev" type="button" value="PREVIOUS"/>
<input id="next" type="button" value="NEXT"/>
And here is the changed CSS:
.content {
position:relative; /**/
width:500px;
height:250px;
margin-right:auto;
margin-left:auto;
background-color:#555;
overflow:hidden; /**/
}
ul.shop-groups {
position:absolute; /**/
left:0px;
background-color: #DDDDDD;
border-bottom: 1px solid #CCCCCC;
width: 999999px;
}
ul.shop-groups a {
color: #fff;
display: block;
font-size: 1.1em;
font-weight: bold;
line-height: 20px;
min-width: 20px;
padding: 2px 15px;
text-align: center;
}
li.shop-items {
position:relative;/**/
float:left;/**/
border: solid 1px #d45;
float : left;
background-color:blue;
height:248px; /**/
width:498px; /**/
}
Upvotes: 3