-
Notifications
You must be signed in to change notification settings - Fork 2
/
MutationObserver.html
54 lines (44 loc) · 1.17 KB
/
MutationObserver.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">
<title>MutationObserver demo</title>
</head>
<style type="text/css">
#box {
display: inline-block;
background-color: aquamarine;
padding: 5px 10px;
cursor: pointer;
}
</style>
<body>
<div id="box">clich me!</div>
<div id="wocao"></div>
<script src="https://code.jquery.com/jquery-1.11.3.js"></script>
<script>
let observer = new MutationObserver(callback)
let article = document.body
let options = {
'childList': true,
'subtree': true
};
observer.observe(article, options);
function callback(arr, observer) {
console.log(arr)
console.log(observer)
}
let index = 0
$("#box").on("click", function () {
for (let i = 0; i < 10; i++) {
$("#wocao").append(`<div>${index}</div>`)
setTimeout(_ => {
let $dom = $(`<div>${index}</div>`)
index++
$("body").append($dom)
}, 1000 * i)
}
})
</script>
</body>
</html>