forked from wuyawei/fe-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscroll.html
More file actions
67 lines (65 loc) · 1.8 KB
/
Copy pathscroll.html
File metadata and controls
67 lines (65 loc) · 1.8 KB
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
<!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>
<style>
.wrapper{
margin: 0;
padding: 0;
}
.wrapper li{
height: 100px;
background-color: red;
color: #fff;
text-align: center;
font-size: 28px;
margin-bottom: 20px;
}
</style>
<body>
<ul class="wrapper">
</ul>
</body>
<script>
const wrapper = document.querySelector('.wrapper');
let total = 100000;
let index = 0;
const page = 100;
const render = (len) => {
const fragment = document.createDocumentFragment();
new Array(len).fill('').forEach(() => {
const li = document.createElement('li');
li.innerHTML = index ++;
fragment.appendChild(li)
})
wrapper.appendChild(fragment);
}
const reFrame = () => {
if (total <= 0) return;
// window.requestAnimationFrame(() => {
// render(page);
// total -= 100;
// reFrame();
// })
window.requestIdleCallback((IdleDeadline) => {
// 核心可以设置回调执行时间,IdleDeadline.timeRemaining() 是留给回调的可用时间,
// IdleDeadline.didTimeout 返回 true,说明时间不够了
// 此时可以跳过本次执行
console.log(IdleDeadline.didTimeout, IdleDeadline.timeRemaining())
if (IdleDeadline.didTimeout) {
reFrame();
return;
};
render(page);
total -= 100;
reFrame();
}, {timeout: 10})
}
// reFrame()
// render(total)
</script>
</html>