/
跑马灯无限往上.html
74 lines (68 loc) · 1.64 KB
/
跑马灯无限往上.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
<!DOCTYPE HTML>
<html>
<script src="../js/jquery-2.1.1.min.js"></script>
<head>
<style type="text/css">
ul {
/*不要margin否则滚动 会有缝隙*/
margin: 0;
}
div {
/*overflow hidden·否则无法盖住下面的内容*/
overflow: hidden;
width: 75px;
height: 100px;
margin-left: 29%;
margin-top: 10%;
background: aqua;
border-top: 1px solid red;
border-bottom: 1px solid red;
}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无缝滚动</title>
</head>
<body>
<div id="ca">
<ul id="c1">
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
<li>7</li>
<li>8</li>
</ul>
<ul id="c2"></ul>
</div>
</body>
<script language="javascript" type="text/javascript">
var c1 = document.getElementById("c1");
var c2 = document.getElementById("c2");
var ca = document.getElementById("ca");
/*将第一个ul的值赋值给第二个 当第一个头部消失时 由第二个来显示*/
c2.innerHTML = c1.innerHTML;
var cas = null;
window.onload = function () {
st();
}
cas = setInterval('st()', 50);
function st() {
//clearInterval(cas);
/*如果滚动长度大于第一个ul的高度 就需要将第一个ul回到原处 */
if (ca.scrollTop >= c1.offsetHeight) {
ca.scrollTop = 0;
} else {
ca.scrollTop ++;
}
/*鼠标移入就清除清除定时器*/
ca.onmouseover = function() {
clearInterval(cas);
}
ca.onmouseout=function() {
cas = setInterval('st()', 50);
}
}
</script>
</html>