-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
48 lines (35 loc) · 1.05 KB
/
index.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
41
42
43
44
45
46
47
48
const container = document.querySelector('.container');
const URL = "https://api.dicebear.com/9.x/pixel-art/svg?seed=";
var count =0;
/*
pt.1
Get a batch of images and append to the container div.
*/
function getrandvalue(){
var getvalue = Math.floor(Math.random()*100);
return `${getvalue}.svg`;
}
function loadImage(numImages=30){
let i=0;
while(i<numImages){
const img = document.createElement('img');
const countImage = document.createElement('p');
countImage.innerHTML= ++count;
img.src = `${URL}${getrandvalue()}`
container.appendChild(img);
container.appendChild(countImage);
i++;
}
}
loadImage();
/*
pt.2
Listen to a scroll event and load more images if we reach the bottom of the window;
*/
window.addEventListener('scroll',()=>{
let offset=1;
console.log((window.scrollY+window.innerHeight),document.documentElement.scrollHeight);
if((window.scrollY+window.innerHeight+offset) >= document.documentElement.scrollHeight){
loadImage();
}
})