Skip to content

Commit

Permalink
Drop image lazy-loading fallback
Browse files Browse the repository at this point in the history
Could present an issue on Safari < 15.4?
  • Loading branch information
simonwiles committed Apr 4, 2023
1 parent 67b1808 commit 42ef9db
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 21 deletions.
20 changes: 0 additions & 20 deletions src/js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,6 @@ const filterSelects = Object.fromEntries(
);
let activeFilters = {};

const enableLazyLoading = (images, root) => {
const imageObserver = new IntersectionObserver(
(entries, observer) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
const image = entry.target;
image.src = image.dataset.src;
image.removeAttribute("data-src");
imageObserver.unobserve(image);
}
});
},
{ root, rootMargin: "0px 0px 100% 0px" },
);
images.forEach((image) => imageObserver.observe(image));
};

const toggleItem = (img, condition = true) => {
if (condition) {
img.style.removeProperty("width");
Expand Down Expand Up @@ -234,9 +217,6 @@ wallContainer.addEventListener("click", ({ target }) => {
}
});

// Hook up lazy loading
enableLazyLoading(wallContainer.querySelectorAll("[data-src]"), wallContainer);

// Initialize MemeWall
memewall = new MemeWall(wallContainer, wallItemToggleCb);
if (window.location.hash) goToMeme(window.location.hash.substring(1));
2 changes: 1 addition & 1 deletion src/pages/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const description =
>
<source srcset={srcsets.webp} type="image/webp" sizes="15vmax" />
<img
data-src={srcsets.jpg}
src={srcsets.jpg}
style={`aspect-ratio:${meme.aspectRatio}`}
loading={idx > 20 ? "lazy" : "eager"}
decoding="async"
Expand Down

0 comments on commit 42ef9db

Please sign in to comment.