1document.addEventListener("DOMContentLoaded", function () { 2 let timeout = null; 3 let lazyImgList = document.querySelectorAll('img.lazy-load'); 4 const windowHeight = window.innerHeight; // Äá» cao mà n hình 5 6 const lazyLoadImage = () => { 7 // áp dụng kỹ thuáºt debounce Äá» giảm sá» lần thá»±c thi hà m khi scroll 8 if (timeout) { 9 clearTimeout(timeout); 10 } 11 12 timeout = setTimeout(() => { 13 const windowYOffset = window.pageYOffset; // vá» trà scroll hiá»n tại 14 15 lazyImgList.forEach((img, index) => { 16 // Load ảnh khi ảnh bưá»c và o khung nhìn mà n hình 17 if (img.offsetTop <= windowYOffset + windowHeight) { 18 img.src = img.dataset?.src; // Chép link ảnh qua thuá»c tÃnh src 19 img.classList.remove('lazy-load'); 20 } 21 }); 22 23 lazyImgList = document.querySelectorAll('img.lazy-load'); // Cáºp nháºt lại list 24 // Xoá event khi Äã load tất cả các ảnh 25 if (lazyImgList.length === 0) { 26 document.removeEventListener('scroll', lazyLoadImage); 27 return; 28 } 29 }, 30); 30 } 31 32 lazyLoadImage(); // load lần Äầu nếu ảnh á» trên cùng trưá»c khi ngưá»i dùng scroll 33 lazyImgList.length && document.addEventListener('scroll', lazyLoadImage); 34})
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.