User:Messing with data/vector.js: Difference between revisions
Jump to navigation
Jump to search
Some logging |
Rely on old jQuery... |
||
| Line 1: | Line 1: | ||
document. | $(document).ready(function() { | ||
console.log("Starting own vector.js"); | console.log("Starting own vector.js"); | ||
var lazyImages = [].slice.call(document.querySelectorAll(".lazy-beta")); | var lazyImages = [].slice.call(document.querySelectorAll(".lazy-beta")); | ||
Revision as of 23:03, 18 June 2024
$(document).ready(function() {
console.log("Starting own vector.js");
var lazyImages = [].slice.call(document.querySelectorAll(".lazy-beta"));
console.log("lazyImages", lazyImages);
if ("IntersectionObserver" in window) {
console.log("Defining observer...");
var lazyImageObserver = new IntersectionObserver(function(entries, observer) {
entries.forEach(function(entry) {
if (entry.isIntersecting) {
var lazyImage = entry.target;
lazyImage.src = lazyImage.dataset.src;
lazyImage.srcset = lazyImage.dataset.srcset;
lazyImage.classList.remove("lazy-beta");
lazyImageObserver.unobserve(lazyImage);
}
});
});
lazyImages.forEach(function(lazyImage) {
console.log("Processing image", lazyImage);
lazyImageObserver.observe(lazyImage);
});
} else {
// Possibly fall back to event handlers here
console.log("Lazy Loading seems to have failed.");
}
});
