-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
51 lines (44 loc) · 1.35 KB
/
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
Loader=document.getElementById("spin")
const photos=document.getElementById("images")
const AK="KY0eAbNlWbjH-u2dcCeZh_PjjyWdziI8-DUPUVHesI4"
const cou = 5
let apiurl ="https://api.unsplash.com/photos/random/?client_id=KY0eAbNlWbjH-u2dcCeZh_PjjyWdziI8-DUPUVHesI4&count=10"
async function getimages(){
try {
const response =await fetch(apiurl)
var img =await response.json()
displayimg(img)
console.log(img)
} catch (error) {
console.log('Error')
}
}
function displayimg(img){
img.forEach((images) => {
// create anchor attribute
var a = document.createElement('a');
a.target = '_blank';
a.href = images.links.html
// Create img attribute
tempimage = document.createElement("img");
tempimage.src=images.urls.small_s3
tempimage.alt = img.alt_description
a.appendChild(tempimage)
photos.appendChild(a)
});
}
window.addEventListener('scroll',(event) => {
if (document.body.scrollHeight - ( scrollY + window.innerHeight) <= 1000 ){
getimages()
}
// console.log('Scrolling...');
// console.log(window.innerHeight)
// console.log(scrollY);
// console.log(document.body.scrollHeight)
});
// loader
// function l (){
// Loader.hidden = false;
// }
getimages()
// l()