-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloading.js
More file actions
43 lines (36 loc) · 1.32 KB
/
loading.js
File metadata and controls
43 lines (36 loc) · 1.32 KB
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
// Add a delay function
function delay(milliseconds) {
return new Promise(resolve => setTimeout(resolve, milliseconds));
}
document.addEventListener("DOMContentLoaded", function () {
const images = document.querySelectorAll("img[data-src]");
const content = document.getElementById("content");
const observer = new IntersectionObserver(
(entries, observer) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const img = entry.target;
const src = img.getAttribute("data-src");
img.setAttribute("src", src);
img.removeAttribute("data-src");
observer.unobserve(img);
}
});
},
{ threshold: 0.5 }
);
images.forEach(img => {
observer.observe(img);
});
async function showContent() {
content.classList.remove("hidden");
await delay(500);
}
async function initializeWebsite() {
document.getElementById("loading").style.display = "flex";
await delay(2000);
document.getElementById("loading").style.display = "none";
await showContent();
}
window.addEventListener("load", initializeWebsite);
});