WEB前端:05_scroll滚动(图片/文字滚动)
2020-12-13 02:29
阅读:407
YPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
标签:style blog class code java ext
scroll滚动(图片/文字滚动)
网站常用效果之一,以下为简化版,用于学习javascript基础知识。
效果图:
scroll滚动(图片/文字滚动)- 纯JS简化版
?
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
|
>
*{margin: 0; padding: 0;} #probox{ position: relative; border: 1px solid #ccc; width:1000px;overflow:hidden;height:120px; margin: 10px auto;} #prolist{ position: relative; width:2000px; height: 120px; list-style: none; margin: 0; padding: 0;} #prolist li {float: left; width: 250px; height: 120px; text-align: center;} #left,#right{ background: #333; color: #fff; padding: 5px; cursor:pointer;}
>
window.onload = function () {
var
probox = document.getElementById( ‘probox‘ );
var
prolist = document.getElementById( ‘prolist‘ );
var
prolistli = prolist.getElementsByTagName( ‘li‘ );
var
btnleft = document.getElementById( ‘left‘ );
var
btnright = document.getElementById( ‘right‘ );
var
cut = prolistli[1].offsetLeft - prolistli[0].offsetLeft;
var
len = prolist.offsetLeft;
var
timer = null ;
function
autoplay() {
if (timer) {
clearInterval(timer);
}
timer = setInterval( function () {
if (prolist.offsetLeft == -cut) {
clearInterval(timer);
prolist.appendChild(prolistli[0]);
prolist.style.left = "0px" ;
} else
{
prolist.style.left = prolist.offsetLeft - 10 + "px" ;
}
}, 30)
}
probox.onmouseover = function () {
clearInterval(o);
}
probox.onmouseout = function () {
o = setInterval(autoplay, 3000);
}
btnleft.onclick = function () {
clearInterval(o);
if (timer) {
clearInterval(timer);
}
timer = setInterval( function () {
if (prolist.offsetLeft == 0) {
clearInterval(timer);
prolist.insertBefore(prolistli[prolistli.length - 1], prolist.firstChild);
prolist.style.left = -cut + "px" ;
} else
{
prolist.style.left = prolist.offsetLeft + 10 + "px" ;
}
}, 30);
o = setInterval(autoplay, 3000);
}
btnright.onclick = function () {
clearInterval(o);
if (timer) {
clearInterval(timer);
}
timer = setInterval( function () {
if (prolist.offsetLeft == -cut) {
clearInterval(timer);
prolist.appendChild(prolistli[0]);
prolist.style.left = "0px" ;
} else
{
prolist.style.left = prolist.offsetLeft - 10 + "px" ;
}
}, 30);
o = setInterval(autoplay, 3000);
}
o = setInterval(autoplay, 3000);
}
|
WEB前端:05_scroll滚动(图片/文字滚动),搜素材,soscw.com
WEB前端:05_scroll滚动(图片/文字滚动)
标签:style blog class code java ext
原文地址:http://www.cnblogs.com/haicheng/p/3718565.html
评论
亲,登录后才可以留言!