Hi,
I have built a preloader animation for a website. On my localhost the animation would run anytime I reload the page but I did not tough that the same would happen when the site is live because I thought that the cashe will save the page. The preloader is on a window load event.
There is also a problem, for some users the page is black, the page is loaded and once the page got loaded the animation runs instead of the animation running while the page is loading.
Is there a way I could fix it?
This is the function of the prelaoder
“`
window.addEventListener(“load”, () => {
const preloader = document.querySelector(“.preloader”);
const preloaderBg = document.querySelectorAll(“.preloader-bg”);
setTimeout(() => {
preloader.classList.add(“preloader-finished”);
preloaderBg.forEach((bg) => {
bg.classList.add(“preloader-finished”);
});
setTimeout(() => {
preloader.parentElement.removeChild(preloader);
}, 500);
}, 3000);
});