-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path67.stop-propogation.html
54 lines (48 loc) · 1.49 KB
/
67.stop-propogation.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.rect {
position: relative;
width: 800px;
height: 600px;
background-color: rgb(248, 232, 232);
border: 1px solid black;
}
.ball {
position: absolute;
width: 150px;
height: 150px;
border-radius: 50%;
background-color: rgb(245, 216, 52);
text-align: center;
border: 1px solid black;
left: 100px;
top: 100px;
}
</style>
</head>
<body>
<div class="rect">
<div class="ball"></div>
</div>
<script>
const rect = document.querySelector(".rect");
const ball = document.querySelector(".ball");
const handler = (event) => {
event.stopPropagation(); // 停止事件物件的傳遞
console.log("target:", event.target);
console.log("current target:", event.currentTarget);
console.log(event.eventPhase);
}
ball.addEventListener("click", handler);
rect.addEventListener("click", handler);
document.addEventListener("click", handler);
window.addEventListener("click", handler);
</script>
</body>
</html>