Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- document.addEventListener("DOMContentLoaded", function() {
- const imageObserver = new IntersectionObserver((entries, imgObserver) => {
- entries.forEach((entry) => {
- if (entry.isIntersecting) {
- const lazyImage = entry.target;
- if (lazyImage.tagName == 'IMG') {
- lazyImage.src = lazyImage.dataset.src;
- } else {
- lazyImage.style.backgroundImage = 'url('+ lazyImage.dataset.src +')';
- }
- lazyImage.classList.remove("gr_images_lazy_load");
- imgObserver.unobserve(lazyImage);
- }
- })
- });
- const arr = document.querySelectorAll(".gr_images_lazy_load");
- arr.forEach((v) => {
- imageObserver.observe(v);
- })
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement