Compare commits

..

2 Commits

Author SHA1 Message Date
6f10adc609 add lazy background image 2026-01-05 13:39:42 +00:00
f09fc24ef6 add hero image size 2026-01-05 13:39:24 +00:00
2 changed files with 28 additions and 1 deletions

View File

@@ -168,5 +168,6 @@ function cors() {
}
$image_srcset = new Utilities\ImageSrcset;
$image_srcset->add(['name' => 'hero', 'width' => 1920, 'height' => 1000]);
$image_srcset->add(['name' => 'hero', 'width' => 1920, 'height' => 1080]);
add_image_size('lazy', 50, 50);
add_image_size('hero', 1920, 1080, true);

View File

@@ -1,6 +1,7 @@
export default function LazyLoadInit()
{
document.addEventListener('DOMContentLoaded', LazyLoad());
document.addEventListener('DOMContentLoaded', LazyBG());
}
function LazyLoad() {
@@ -31,3 +32,28 @@ function LazyLoad() {
// Possibly fall back to a more compatible method here
}
}
function LazyBG() {
var lazyImages = [].slice.call(document.querySelectorAll('.lazy-bg'));
if ('IntersectionObserver' in window) {
let lazyImageObserver = new IntersectionObserver(function(entries, observer) {
entries.forEach(function(entry) {
if (entry.isIntersecting) {
let lazyImage = entry.target;
lazyImage.computedStyleMap.backgroundImage = `url(${lazyImage.dataset.bg})`;
lazyImage.classList.remove('lazy-bg');
lazyImageObserver.unobserve(lazyImage);
}
});
});
lazyImages.forEach(function(lazyImage) {
lazyImageObserver.observe(lazyImage);
});
} else {
// Possibly fall back to a more compatible method here
}
}