-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path延迟消失.html
65 lines (50 loc) · 1.17 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.div1{
width: 20px;
height: 20px;
background: #ccc;
margin-bottom: 10px;
cursor: pointer;
}
.div2{
width: 60px;
height: 20px;
background: red;
cursor: pointer;
display: none;
}
</style>
</head>
<body>
<div class="div1"></div>
<div class="div2"></div>
<script>
var div1 = document.querySelector('.div1');
var div2 = document.querySelector('.div2');
var timerId = 0;
div1.onmouseover = function (){
div2.style.display = 'block';
}
div1.onmouseout = function (){
autoPlay();
}
div2.onmouseover = function (){
clearTimeout(timerId);
}
div2.onmouseout = function (){
autoPlay();
}
// 封装函数
function autoPlay(){
timerId = setTimeout(function (){
div2.style.display = 'none';
},300);
}
</script>
</body>
</html>