-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample.html
68 lines (60 loc) · 1.66 KB
/
example.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
66
67
68
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=Edge">
<meta charset="utf-8">
<title>When In Dom Example</title>
</head>
<body>
<!-- a lot of divs just for testing -->
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div id="test"></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div></div>
<div></div>
<div></div>
<div></div>
<script src="whenInDom.min.js" type="text/javascript"></script>
<script type="text/javascript">
var a = document.createElement('div');
var b = document.createElement('div');
var t1, t2;
var obs1 = new WhenInDOM(a, function () {
t2 = (new Date()).getTime();
a.appendChild(document.createTextNode('I got inserted into DOM. ' + 'Time from insertion to callback: ' + (t2 - t1) + "ms"));
});
// insert div into another but not dom
setTimeout(function () {
b.appendChild(a);
b.appendChild(document.createTextNode('I am a div inserted into another div , but not to dom at once'));
}, 1000);
// insert parent div to dom
setTimeout(function () {
document.getElementById('test').appendChild(b);
t1 = (new Date()).getTime();
}, 2000);
</script>
</body>
</html>