-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path01-a-auto-scroll.js
44 lines (30 loc) · 908 Bytes
/
01-a-auto-scroll.js
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
import { generateData, removeAllChildren } from "./utils.js"
removeAllChildren(boxEl)
document.title = 'auto-scroll'
const dataSource = generateData(10000)
let container
function initRender() {
container = document.createElement('div')
renderChildren(container)
boxEl.appendChild(container)
}
function renderChildren(parent) {
removeAllChildren(parent)
const frag = document.createDocumentFragment()
for(let i = 0; i < dataSource.length; i++) {
const child = document.createElement('div')
child.innerText = dataSource[i].title
child.dataset.index = dataSource[i].idx
frag.appendChild(child)
}
parent.appendChild(frag)
}
initRender()
function scrollHanlder() {
console.log('scroll in 01')
renderChildren(container)
}
boxEl.addEventListener('scroll', scrollHanlder)
export function removeAllListeners() {
boxEl.removeEventListener('scroll', scrollHanlder)
}