-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path无缝滚动.html
More file actions
48 lines (47 loc) · 1.35 KB
/
无缝滚动.html
File metadata and controls
48 lines (47 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无缝滚动</title>
<style type="text/css">
*{margin:0;padding:0;}
#div2{width:600px;overflow:hidden;position:relative;left:200px;}
#div1{position:relative;left:0px;width:1200px;}
#div1 li{list-style-type: none;float:left;width:200px;height:180px;
}
img{width:100%;height:100%;}
</style>
<script>
window.onload=function(){
var oUl=document.getElementById('ul1');
var oDiv=document.getElementById('div1');
var oBtn=document.getElementById('btn1');
var t=0;
oUl.innerHTML = oUl.innerHTML + oUl.innerHTML;
var speed = 20;//速度,必须是oUl.offsetWidth能整除的数;
oBtn.onclick=function(){
clearInterval(t);
t=setInterval(function(){
if(oDiv.offsetLeft <= -oUl.offsetWidth/2){
oDiv.style.left = -speed+'px';//因为判断的时候已经到了边界了,所以应该执行下次
}else{
oDiv.style.left = oDiv.offsetLeft - speed+'px';
}
},50);
}
}
</script>
</head>
<body>
<input id="btn1" value="开始" type="button"/>
<div id="div2">
<div id="div1">
<ul id="ul1">
<li><img src="1.jpg"></li>
<li><img src="2.jpg"></li>
<li><img src="3.jpg"></li>
</ul>
</div>
</div>
</body>
</html>