Skip to content

Instantly share code, notes, and snippets.

@ijurko
Created November 25, 2024 10:00
Show Gist options
  • Save ijurko/989dab65985f0747e3e31f9de175a9a4 to your computer and use it in GitHub Desktop.
Save ijurko/989dab65985f0747e3e31f9de175a9a4 to your computer and use it in GitHub Desktop.
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