<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>无缝滚动</title>
<style>
*{margin: 0; padding: 0;}
#div1{width: 534px; height: 108px; margin: 100px auto; position: relative;
overflow: hidden;}
#div1 ul{position: absolute; left: 0; top: 0;}
#div1 ul li{float: left; width: 178px; height: 108px; list-style: none;}
</style>
</head>
<body>
<a href="javascript:;">向左走</a>
<a href="javascript:;">向右走</a>
<a href="javascript:;">加速</a>
<div id="div1">
<ul>
<li><img src="img/1.jpg"></li>
<li><img src="img/2.jpg"></li>
<li><img src="img/3.jpg"></li>
</ul>
</div>
<script>
var speed=-2;
var oDiv=document.getElementById('div1');
var oUl=oDiv.getElementsByTagName('ul')[0];
var aLi=oUl.getElementsByTagName('li');
function show()
{
if(oUl.offsetLeft<-oUl.offsetWidth/2)
{oUl.style.left=0;}
if(oUl.offsetLeft>0)
{oUl.style.left=-oUl.offsetWidth/2+'px';}
oUl.style.left=oUl.offsetLeft+speed+'px';
}
oUl.innerHTML=oUl.innerHTML+oUl.innerHTML;
oUl.style.width=aLi[0].offsetWidth*aLi.length+'px';
var timer=setInterval(show,30);
oDiv.οnmοuseοver=function()
{
clearInterval(timer);
}
oDiv.οnmοuseοut=function()
{
timer=setInterval(show,30);
}
document.getElementsByTagName('a')[0].οnclick=function()
{
speed=-2;
}
document.getElementsByTagName('a')[1].οnclick=function()
{
speed=2;
}
document.getElementsByTagName('a')[2].οnclick=function()
{
if(speed>0)
speed++;
else
speed--;
}
</script>
</body>
</html>
<html>
<head>
<meta charset="UTF-8">
<title>无缝滚动</title>
<style>
*{margin: 0; padding: 0;}
#div1{width: 534px; height: 108px; margin: 100px auto; position: relative;
overflow: hidden;}
#div1 ul{position: absolute; left: 0; top: 0;}
#div1 ul li{float: left; width: 178px; height: 108px; list-style: none;}
</style>
</head>
<body>
<a href="javascript:;">向左走</a>
<a href="javascript:;">向右走</a>
<a href="javascript:;">加速</a>
<div id="div1">
<ul>
<li><img src="img/1.jpg"></li>
<li><img src="img/2.jpg"></li>
<li><img src="img/3.jpg"></li>
</ul>
</div>
<script>
var speed=-2;
var oDiv=document.getElementById('div1');
var oUl=oDiv.getElementsByTagName('ul')[0];
var aLi=oUl.getElementsByTagName('li');
function show()
{
if(oUl.offsetLeft<-oUl.offsetWidth/2)
{oUl.style.left=0;}
if(oUl.offsetLeft>0)
{oUl.style.left=-oUl.offsetWidth/2+'px';}
oUl.style.left=oUl.offsetLeft+speed+'px';
}
oUl.innerHTML=oUl.innerHTML+oUl.innerHTML;
oUl.style.width=aLi[0].offsetWidth*aLi.length+'px';
var timer=setInterval(show,30);
oDiv.οnmοuseοver=function()
{
clearInterval(timer);
}
oDiv.οnmοuseοut=function()
{
timer=setInterval(show,30);
}
document.getElementsByTagName('a')[0].οnclick=function()
{
speed=-2;
}
document.getElementsByTagName('a')[1].οnclick=function()
{
speed=2;
}
document.getElementsByTagName('a')[2].οnclick=function()
{
if(speed>0)
speed++;
else
speed--;
}
</script>
</body>
</html>