$w.onReady(() => {
// Select all images that need lazy loading
const lazyImages = $w('Image').filter(img => img.link === null); // Filter images with no link or specific criteria
// Function to lazy load an image
function lazyLoadImage(img) {
const dataSrc = img.src; // Assuming the placeholder src is initially blank or a loading image
const actualSrc = img.dataSrc; // Assuming you set the real source in a custom attribute (e.g., "dataSrc")
if (actualSrc) {
img.src = actualSrc; // Set the actual image source
img.dataSrc = ''; // Clear the data source to avoid re-triggering
}
}
// Attach `onViewportEnter` to each lazy-load image
lazyImages.forEach(img => {
img.onViewportEnter(() => lazyLoadImage(img));
});
});