My website is filled with numerous images categorized into 5 different groups, causing it to load slowly.
To improve loading times, I have assigned each image a "data-src" attribute containing its actual source. Then, when a specific category is selected (clicked), I update the source attribute of all images in that category by looping through them.
Here's an example of how I structure my HTML:
<img loading="lzay" class="post_image" data-src="https://i.ibb.co/FswR5KB/Pics-Art-06-22-07-48-49.jpg" src="https://i.ibb.co/FswR5KB/Pics-Art-06-22-07-48-49.jpg">
In my JavaScript code, I iterate through the selected images within a for loop like so:
for(i = 0; i< selection.length; i++){
let data_src = selection[i].children[2].getAttribute("data-src");;
selection[i].children[2].src = data_src;
}
I am now facing a challenge where I need to determine when all the images from a particular category have finished loading. Even though there is additional code that should execute after the for loop finishes, I want to ensure that it only runs once every image in the category has loaded onto the page.