Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- document.addEventListener("DOMContentLoaded", function() {
- var lazyImages = document.querySelectorAll('img[lazy-images');
- function handlerLazyLoadImages() {
- Array.prototype.forEach.call(lazyImages, function(img) {
- if ((img.getBoundingClientRect().top <= window.innerHeight && img.getBoundingClientRect().bottom >= 0) && getComputedStyle(img).display != 'none') {
- img.setAttribute('src', img.getAttribute('lazy-images'));
- img.removeAttribute('lazy-images');
- }
- });
- lazyImages = document.querySelectorAll('img[lazy-images');
- }
- handlerLazyLoadImages();
- document.addEventListener('scroll', handlerLazyLoadImages);
- window.addEventListener("resize", handlerLazyLoadImages);
- window.addEventListener("orientationchange", handlerLazyLoadImages);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement