-
Notifications
You must be signed in to change notification settings - Fork 0
/
13.无缝滚动.html
106 lines (98 loc) · 2.35 KB
/
13.无缝滚动.html
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
/*#div1{
width: 200px;
height: 200px;
background: #CCCCCC;
position: absolute;
}*/
*{
margin: 0;
padding: 0;
}
#div1{
width: 712px;
height: 108px;
margin: 100px auto;
position: relative;
overflow: hidden;
}
#div1 ul{
position: absolute;
left: 0;
top: 0;
}
#div1 ul li{
float: left;
height: 108px;
width: 178px;
list-style: none;
}
#div1 ul li img{
height: 108px;
width: 178px;}
</style>
<script type="text/javascript">
/*
window.onload=function(){
setInterval(function(){
oDiv=document.getElementById("div1");
oDiv.style.left=oDiv.offsetLeft+2+'px';
},50)
}*/
window.onload=function(){
var oDiv=document.getElementById("div1");
var oUl=oDiv.getElementsByTagName("ul")[0];
var aLi=oUl.getElementsByTagName("li");
var speed=-2;
oUl.innerHTML=oUl.innerHTML+oUl.innerHTML;
oUl.style.width=aLi[0].offsetWidth*aLi.length+'px';
function move(){
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';
}
var timer=setInterval(move,30);
oDiv.onmouseover=function(){
clearInterval(timer);
}
oDiv.onmouseout=function(){
timer=setInterval(move,30);
}
document.getElementsByTagName("a")[0].onclick=function(){
speed=-2;
}
document.getElementsByTagName("a")[1].onclick=function(){
speed=2;
}
//速度没调好
// document.getElementsByTagName("button")[0].onclick=function(){
// speed=userspeed.value;
// }
}
</script>
</head>
<body>
<!--<div id="div1"></div>-->
<a href="javascript:;">向左走</a>
<a href="javascript:;">向右走</a><br />
<input type="text" name="" id="input1" value="2" />
<button>设置速度</button>
<div id="div1">
<ul>
<li><img src="img/scroll/1.jpg"/></li>
<li><img src="img/scroll/2.jpg"/></li>
<li><img src="img/scroll/3.jpg"/></li>
<li><img src="img/scroll/4.jpg"/></li>
</ul>
</div>
</body>
</html>