I have a gif that appears as my site is loading however the gif disappears and the page appears after everything has loaded except the background videos.
How could I have the gif fade away only after the background images have loaded. I am fairly new to javascript so i'd like a guided code on how to do this please
Here's the code i currently use
//preloader
var loader = document.querySelector(".loader")
window.onload.addEventListener("load", vanish)
function vanish() {
loader.classList.add("dissapear")
}
.loader {
position: fixed;
top: 0;
left: 0;
z-index: 4;
background-color: #36395A;
height: 100%;
width: 100%;
display: flex;
justify-content: center;
align-items: center;
}
.dissapear {
animation: vanish 1s forwards;
}
@keyframes vanish {
100% {
opacity: 0;
visibility: hidden;
}
}
<div class="loader">
<img src="https://catulu.club/images/ch1-img.159861e81e6dc4bfca11.gif" alt="">
</div>