图片Slider 带左右按钮的js示例

时间:2021-05-25

复制代码 代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:///ajax/libs/jquery/1.4.1/jquery.js"></script>
<style type="text/css">
body,ul,li { padding:0; margin:0}
ul,li { list-style:none}
.img-scroll { position:relative; margin:20px auto; width:440px;}
.img-scroll .prev,.img-scroll .next { position:absolute; display:block; width:50px; height:100px; background-color:#000;
top:0; color:#FFF; text-align:center; line-height:100px}
.img-scroll .prev { left:0}
.img-scroll .next { right:0}
.img-list { position:relative; width:320px; height:100px; margin-left:60px; overflow:hidden}
.img-list ul { width:9999px;}
.img-list li { float:left; display:inline; width:100px; margin-right:10px; height:100px; background-color:#BDBDDF; text-align:center; line-height:100px;}
</style>
</head>

<body>
<div class="img-scroll">
<span class="prev">prev</span>
<span class="next">next</span>
<div class="img-list">
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
</ul>
</div>
</div>
<script type="text/javascript">
function DY_scroll(wraper,prev,next,img,speed,or)
{
var wraper = $(wraper);
var prev = $(prev);
var next = $(next);
var img = $(img).find('ul');
var w = img.find('li').outerWidth(true);
var s = speed;
next.click(function()
{
img.animate({'margin-left':-w},function()
{
img.find('li').eq(0).appendTo(img);
img.css({'margin-left':0});
});
});
prev.click(function()
{
img.find('li:last').prependTo(img);
img.css({'margin-left':-w});
img.animate({'margin-left':0});
});
if (or == true)
{
ad = setInterval(function() { next.click();},s*1000);
wraper.hover(function(){clearInterval(ad);},function(){ad = setInterval(function() { next.click();},s*1000);});

}
}
DY_scroll('.img-scroll','.prev','.next','.img-list',3,false);
</script>

</body>
</html>

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章