pull in v11.0.1 from upstream
This commit is contained in:
33
resources/js/lib/Lazy.js
Normal file
33
resources/js/lib/Lazy.js
Normal file
@@ -0,0 +1,33 @@
|
||||
export default function LazyLoadInit()
|
||||
{
|
||||
document.addEventListener('DOMContentLoaded', LazyLoad());
|
||||
}
|
||||
|
||||
function LazyLoad() {
|
||||
|
||||
var lazyImages = [].slice.call(document.querySelectorAll('img.lazy'));
|
||||
|
||||
if ('IntersectionObserver' in window) {
|
||||
let lazyImageObserver = new IntersectionObserver(function(entries, observer) {
|
||||
entries.forEach(function(entry) {
|
||||
if (entry.isIntersecting) {
|
||||
let lazyImage = entry.target;
|
||||
lazyImage.src = lazyImage.dataset.src;
|
||||
|
||||
if(lazyImage.dataset.srcset) {
|
||||
lazyImage.srcset = lazyImage.dataset.srcset;
|
||||
}
|
||||
|
||||
lazyImage.classList.remove('lazy');
|
||||
lazyImageObserver.unobserve(lazyImage);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
lazyImages.forEach(function(lazyImage) {
|
||||
lazyImageObserver.observe(lazyImage);
|
||||
});
|
||||
} else {
|
||||
// Possibly fall back to a more compatible method here
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user