无缝自动滚动

主要是最后一个要跟第一个一样就行了,

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="Content-Type" content="text/html; charset=utf8">
<title>无标题文档</title>

<style type="text/css">
*
{margin:0;padding:0;}
ul
{list-style:none}
.red
{ background:red;}
.blue
{ background:blue}
.wrap
{width:500px;height:300px;overflow:hidden;position:relative;margin:55px auto}
.inner
{position:absolute;left:0;top:0;}
.wrap li
{float:left;width:500px;height:300px;}
.orange
{ background:orange}
</style>

<script type="text/javascript" src="jquery-1.6.min.js">
</script>

</head>

<body>

<div class="wrap">
<div class="inner">
<ul>
<li class="red"></li>
<li class="blue"></li>
<li class="red"></li>
</ul>
</div>
</div>

<script type="text/javascript">
$(
".inner").css("width",($("li").length*$("li").width())+"px");
var cur =0;
function autoScroll(){

if(cur ==$("li").length-1){
cur
=0;
$(
".inner").css("left","0px")
}
cur
++;
$(
".inner").animate({left:-500*cur},300);


}
setInterval(
function(){
autoScroll()
},
3000)
</script>


</body>
</html>



posted @ 2011-10-29 22:41  深蓝色梦想  阅读(143)  评论(0编辑  收藏