Created
November 25, 2024 10:00
-
-
Save ijurko/989dab65985f0747e3e31f9de175a9a4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default class Loader { | |
constructor(ctrl) { | |
this.loader = document.querySelector(".js-loader"); | |
this.controller = ctrl; | |
this.nav = document.querySelector(".js-main-navigation-wrapper"); | |
} | |
init() { | |
document.querySelector("html").classList.add("overflow-hidden"); | |
if ("onbeforeunload" in window) { | |
window.onbeforeunload = () => { | |
this.loader.classList.remove("hide"); | |
this.loader.classList.add("show"); | |
}; | |
} | |
if ("onpageshow" in window) { | |
window.onpageshow = () => { | |
setTimeout(() => { | |
this.hideLoader(); | |
}, 100); | |
}; | |
} else { | |
setTimeout(() => { | |
this.hideLoader(); | |
}, 100); | |
} | |
if (this.loader.classList.contains("show")) { | |
this.hideLoader(); | |
} | |
} | |
hideLoader() { | |
this.loader.classList.remove("show"); | |
this.loader.classList.add("hide"); | |
setTimeout(() => { | |
document.querySelector("html").classList.remove("overflow-hidden"); | |
}, 30); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment