lazysizes or lazyload.
Why does it work this way?
The initial image upload (or its placeholder) uses the value data:image/gif;base64,... in the attribute src so that the browser can display a minimal transparent or empty placeholder. The library then replaces it with the physical path specified in data-src as soon as the image enters the visible area.
If the setting is enabled on your ASPRO website: Use "lazy" (LazyLoad) image loading (displaying only visible images) and you need to disable it only for a specific block on the page, you can do the following:
JavaScript solution for the class .exclude-lazy img
Add a code that immediately sets the attribute value. src for images located in containers with the class .exclude-lazy, and eliminates lazy loading:
document.addEventListener("DOMContentLoaded", () => { const images = document.querySelectorAll(".exclude-lazy img.lazyload"); images.forEach((img) => { if (img.dataset.src) { img.src = img.dataset.src; // Setting src based on data-src img.removeAttribute("data-src"); // Removing the data-src attribute if it is no longer needed img.classList.remove("lazyload"); // Removing the lazyload class } }); });
Explanation:
- Image Search:
document.querySelectorAll(".exclude-lazy img.lazyload")— select only images with the class.lazyloadinside the container with the class.exclude-lazy. - Replacement
src: For each such image, we replace the attributesrcon the valuedata-src. - Deleting attributes: Removing the attribute
data-srcAnd the classlazyloadto disable lazy loading and make the image look normal.
This code ensures that the images with the class exclude-lazy they will not be subject to lazy loading and will load immediately using their attribute. data-src.