Learn how to identify a dead car battery and find solutions to get your vehicle up and running again. Visit our website for valuable...
3 min read
bottom of page
// Lazy load images and other elements
function lazyLoadElements() {
const elements = document.querySelectorAll('.lazy-load');
const observer = new IntersectionObserver((entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
const element = entry.target;
element.src = element.dataset.src;
observer.unobserve(element);
}
});
}, {
rootMargin: '50px',
});
elements.forEach((element) => {
observer.observe(element);
});
}
// Run the lazy load function on page load
document.addEventListener('DOMContentLoaded', lazyLoadElements);