-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
29 lines (22 loc) · 735 Bytes
/
script.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
document.addEventListener("contextmenu", function(e){
e.preventDefault();
}, false);
// ----------------- Infinity Scrolling - Vanilla JavaScript ---------------
let wrapper = document.querySelector('.wrapper')
let result = []
let postId = 1
let fetchingData = false
document.addEventListener('scroll', function (){
if (fetchingData) return
fetchingData = true
fetch(`https://jsonplaceholder.typicode.com/comments?postId=${postId}`)
.then(response => response.json())
.then(data => result = data)
for (let i = 0; i < result.length; i++) {
wrapper.innerHTML += `<h1>${result[i].name}</h1>`
}
setTimeout(() => {
fetchingData = false
postId++
}, 300);
})