forked from jackfrued/Python-100-Days
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample04.html
48 lines (45 loc) · 1.01 KB
/
example04.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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
* {
margin: 0;
padding: 0;
}
#container {
width: 940px;
height: 430px;
margin: 0 auto;
}
</style>
</head>
<body>
<!-- 绑定事件除了用标签属性之外还有哪些更好的做法 -->
<div id="container" onmouseover="stopChange()" onmouseout="resumeChange()">
<img id="adv" src="img/slide-1.jpg">
</div>
<script>
// 除了getElementById还有哪些获取元素的方法
// - getElementsByTagName()
// - getElementsByClassName()
// - querySelector()
// - querySelectorAll()
var img = document.getElementById('adv');
var currentIndex = 0;
var timerId = 0;
resumeChange();
function stopChange() {
window.clearInterval(timerId);
}
function resumeChange() {
timerId = setInterval(function() {
currentIndex += 1;
currentIndex %= 4;
img.src = 'img/slide-' + (currentIndex + 1) + '.jpg';
}, 3000);
}
</script>
</body>
</html>