-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlunbotu.js
61 lines (50 loc) · 1.67 KB
/
lunbotu.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
let jian = document.getElementsByClassName('jian')[0];
let left = document.getElementsByClassName('left')[0];
let right = document.getElementsByClassName('right')[0];
let demo = document.getElementsByClassName('demo')[0];
let button = document.getElementsByTagName('span');
let speed = 300;
function timer() {
if (parseInt(jian.style.left) >= -1200) {
jian.style.left = parseInt(jian.style.left) - speed + "px";
jian.classList.add('ahh');
} else if (parseInt(jian.style.left) == -1500) {
jian.classList.remove("ahh");
jian.style.left = "0px";
};
};
let st;
st = setInterval(timer, 2000);
demo.addEventListener('mouseout', function () {
st = setInterval(timer, 2000);
});
demo.addEventListener('mouseover', function () {
clearInterval(st);
});
left.onclick = function () {
if (parseInt(jian.style.left) <= 0) {
jian.classList.add('ahh');
jian.style.left = parseInt(jian.style.left) + speed + "px";
}
if (parseInt(jian.style.left) > 0) {
jian.classList.remove("ahh");
jian.style.left = "-1800px";
jian.style.left = parseInt(jian.style.left) + speed + "px";
}
};
right.onclick = function () {
if (parseInt(jian.style.left) >= -1800) {
jian.classList.add('ahh');
jian.style.left = parseInt(jian.style.left) - speed + "px";
} if (parseInt(jian.style.left) == -2100) {
jian.classList.remove("ahh");
jian.style.left = "0px";
jian.style.left = parseInt(jian.style.left) - speed + "px";
}
};
let sum = -300;
for (let i = 0; i < button.length; i++){
button[i].onmouseover = function () {
jian.style.left = sum * (i+1) + "px";
}
};