您的浏览器禁用了Javascript,可能无法正常浏览我们的网站,请更改后再进行浏览,谢谢
主 题: 无缝滚动
已阅:1427 / 回复:0(楼主)
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无缝滚动</title>
<style>
* { margin: 0; padding: 0; }
.other { width: 100%; height: 50px; background: #F00; }
.main { width: 400px; height: 130px; margin: 0 auto; border: 1px solid #000; overflow: hidden; position: relative; }
.banner a { display: block; float: left; margin: 15px 0 0 15px; }
.banner { position: absolute; width: 800%; }
#wrap1,
#wrap2 { float: left; }
.text { text-align: center; }
#wrap1 a,
#wrap2 a { text-decoration: none; }
#wrap1 span,
#wrap2 span { display: block; width: 100px; height: 100px; border: 1px solid #000; font-size: 36px; text-align: center;

background: #999; }
</style>
</head>
<body>
<div class="other">
</div>
<div class="text">
<a href="javascript:void(0)" id="left">向左</a> <a href="javascript:void(0)" id="right">向右</a>
</div>
<div class="main" id="main">
<div class="banner" id="banner">
<div id="wrap1">
<a href="#"><span>1</span></a><a href="#"><span>2</span></a><a href="#"><span>3</span></a><a

href="#"><span>4</span></a><a href="#"><span>5</span></a>
</div>
<div id="wrap2">
</div>
</div>
</div>
<div class="other">
</div>
</body>
</html>
<script type="text/javascript">
window.onload=function(){
speed=-1;
move=getId('banner');
getId('wrap2').innerHTML=getId('wrap1').innerHTML;
var time=setInterval(automove,10);
getId('main').onmouseover=function(){
clearInterval(time);
}
getId('main').onmouseout=function(){
time=setInterval(automove,10);
}
getId('left').onclick=function(){
speed=-1;
}
getId('right').onclick=function(){
speed=1;
}
}
function getId(id){
return document.getElementById(id);
}
function automove(){
if(parseInt(move.style.left)<= -getId('wrap1').offsetWidth){
move.style.left=0+'px';
}
if(move.offsetLeft>0){
move.style.left=-getId('wrap1').offsetWidth+'px';
}
move.style.left=move.offsetLeft+speed+'px';
}
</script>

个性签名
建网站188元 0531-66814598
作者:xueok (2013-3-23 20:56:42)
188元建网站 免费试用 满意付款 0531-82862131

目前不允许游客回复,请 登录 注册 发贴.