thenitesharya

LazyLoad Javascript by The Nitesh Arya

Apr 10th, 2020
2,727
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. document.addEventListener("DOMContentLoaded",function(){var e=[].slice.call(document.querySelectorAll("img.lazy"));if("IntersectionObserver"in window){let n=new IntersectionObserver(function(e,t){e.forEach(function(e){if(e.isIntersecting){let t=e.target;t.src=t.dataset.src,t.classList.remove("lazy"),n.unobserve(t)}})});e.forEach(function(e){n.observe(e)})}});
  2.  
  3. Example
  4. <img class="lazy" data-src="yourimage.jpg" />
  5.  
  6. It will work in all image formate.... The Nitesh Arya
Add Comment
Please, Sign In to add comment