-
Notifications
You must be signed in to change notification settings - Fork 0
/
requestAnimationFrame.html
32 lines (32 loc) · 1.05 KB
/
requestAnimationFrame.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
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<div id="container"></div>
<script>
let index = 0;
let id = 0;
let total = 500;
let container = document.getElementById('container');
function load() {
index += 20;
if (index < total) {
requestAnimationFrame(() => {
for (let i = 0; i < 20; i++) {
let fragment = document.createDocumentFragment();
let li = document.createElement('li');
li.innerHTML = id++;
fragment.appendChild(li);
container.appendChild(fragment);
}
load();
});
}
}
load();
</script>
</body>
</html>