Is it possible to create a loading overlay that remains visible until the first image on a webpage is fully loaded, instead of using setTimeout and then implementing lazy loading for subsequent images?
My current solution using setTimeout is not effective as there is a noticeable gap between the loader disappearing and the image appearing. The image URLs are obtained from a Wordpress API, and I am working within a template structure.
I want to ensure that users do not see a blank state by showing a loading overlay until the initial image is completely loaded. Here's the code snippet I have tried:
var img = document.querySelector("#img");
img.onload = function(){
document.getElementById("loading").style.display = "none"
}
Due to restrictions on using jQuery for this school project, I have explored various alternatives with no success. Even after adding console.log("loaded")
upon image load, nothing seems to work smoothly.