-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcircularly.html
114 lines (114 loc) · 3.42 KB
/
circularly.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
107
108
109
110
111
112
113
114
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>circularly</title>
<style>
*{
margin: 0;
padding: 0;
}
#container{
height: 100px;
width: 165px;
margin: 0 auto;
overflow: hidden;
border: 1px solid;
position: relative;
}
#container div{
height: 100px;
width: 50px;
background-color: black;
color: white;
position: absolute;
top:0;
}
.block1{
left:0;
}
.block2 {
left: 55px;
}
.block3{
left: 110px;
}
.block4{
left: 165px;
}
</style>
</head>
<body>
<div id="container">
<div class="block1">1</div>
<div class="block2">2</div>
<div class="block3">3</div>
<div class="block4">4</div>
</div>
<button id="btn">back</button>
<script>
(function () {
var oContainer = document.getElementById("container");
var aDiv = oContainer.getElementsByTagName("div");
var oBtn = document.getElementById("btn");
var bFlag = true;
var timer = setInterval(function () {
for(var i=0;i<aDiv.length;i++){
aDiv[i].style.left = (aDiv[i].offsetLeft - 1) + 'px';
if(aDiv[i].offsetLeft <= -(aDiv[i].offsetWidth+5)){
aDiv[i].style.left = 165 + 'px';
}
}
},10);
oContainer.onmouseover = function () {
clearInterval(timer);
};
oContainer.onmouseout = function () {
if(!bFlag){
timer = setInterval(function () {
for(var i=0;i<aDiv.length;i++){
aDiv[i].style.left = (aDiv[i].offsetLeft + 1) + 'px';
if(aDiv[i].offsetLeft >= 170){
aDiv[i].style.left = -50 + 'px';
}
}
},10);
}else{
timer = setInterval(function () {
for(var i=0;i<aDiv.length;i++){
aDiv[i].style.left = (aDiv[i].offsetLeft - 1) + 'px';
if(aDiv[i].offsetLeft <= -(aDiv[i].offsetWidth+5)){
aDiv[i].style.left = 165 + 'px';
}
}
},10);
}
};
oBtn.onclick = function () {
clearInterval(timer);
if(bFlag){
timer = setInterval(function () {
for(var i=0;i<aDiv.length;i++){
aDiv[i].style.left = (aDiv[i].offsetLeft + 1) + 'px';
if(aDiv[i].offsetLeft >= 170){
aDiv[i].style.left = -50 + 'px';
}
}
},10);
bFlag=!bFlag;
}else{
timer = setInterval(function () {
for(var i=0;i<aDiv.length;i++){
aDiv[i].style.left = (aDiv[i].offsetLeft - 1) + 'px';
if(aDiv[i].offsetLeft <= -(aDiv[i].offsetWidth+5)){
aDiv[i].style.left = 165 + 'px';
}
}
},10);
bFlag = !bFlag;
}
}
})();
</script>
</body>
</html>