-
Notifications
You must be signed in to change notification settings - Fork 5
/
render_big_data.html
42 lines (41 loc) · 1.3 KB
/
render_big_data.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<ul>控件</ul>
<script>
setTimeout(()=> {
//插入十万条数据
const total = 100000;
//一次插入20条,如果觉得性能不好就减少
const once = 20;
const loopCount = total/once;
let countOfRender = 0;
let ul = document.querySelector('ul');
function add () {
//优化性能,插入不能造成重排
const fragment = document.createDocumentFragment();
for(let i=0;i<once;i++) {
const li = document.createElement('li');
li.innerText = Math.floor(Math.random()*total);
fragment.appendChild(li);
}
ul.appendChild(fragment);
countOfRender += 1;
loop();
}
function loop(){
if(countOfRender < loopCount) {
window.requestAnimationFrame(add);
}
}
loop();
},0)
</script>
</body>
</html>