gpt4 book ai didi

javascript - 滑动 li 元素

转载 作者:搜寻专家 更新时间:2023-10-31 08:35:53 24 4
gpt4 key购买 nike

我正在尝试找到一种方法来制作 li 元素幻灯片。我可以将它们全部放在一条线上(请参阅我的 fiddle )并将它们放入 ul 宽度中。但是当我点击 NEXT 按钮时,我希望它们向右滑动以显示隐藏的 li

我的 fiddle :http://jsfiddle.net/5cmR7/

Smiliar Fiddle:http://jsfiddle.net/L5yEA/

编辑:我想要类似 this 的东西但以更好的方式构建,并且在单击 NEXT 时更加精确。

最佳答案

这就是你所需要的:

jsBin demo

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();
});

只需为您的按钮提供一个ID:

<input id="prev" type="button" value="PREVIOUS"/>
<input id="next" type="button" value="NEXT"/>

这是更改后的 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; /**/
}

关于javascript - 滑动 li 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11253477/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com