-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
25 lines (25 loc) · 871 Bytes
/
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
"use strict";
const images = document.querySelectorAll("img[data-src]");
const imageBoxes = document.querySelectorAll(".grid-item");
const btn = document.querySelector("button");
const allLazyClass = document.querySelectorAll(".lazy");
let counter = 0;
for (let i = 0; i < images.length; i++) {
const newURL = images[i].getAttribute("data-src");
if (newURL)
images[i].src = newURL;
images[i].addEventListener("load", () => {
counter++;
imageBoxes[i].classList.add("loaded");
if (counter === images.length) {
console.log("all images loaded");
imageBoxes.forEach((i) => {
i.classList.remove("loaded");
i.classList.remove("lazy");
});
}
});
}
btn === null || btn === void 0 ? void 0 : btn.addEventListener("click", () => {
location.reload();
});