Skip to content

Commit

Permalink
fix: remove blurred placeholder images from behind loaded images
Browse files Browse the repository at this point in the history
  • Loading branch information
doinkythederp committed Oct 20, 2024
1 parent 4f74c5d commit bed123c
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/components/Image.astro
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const svgUrl = `url("data:image/svg+xml;charset=utf-8,${getImageBlurSvg({

<AstroImage
{...Astro.props}
style=`--placeholder:${svgUrl};${Astro.props.style}`
style=`--placeholder:${svgUrl};${Astro.props.style ?? ""}`
class:list={[{ placeholder: placeholder }, Astro.props["class:list"]]}
/>

Expand All @@ -61,9 +61,10 @@ const svgUrl = `url("data:image/svg+xml;charset=utf-8,${getImageBlurSvg({

<script>
const preloadImages =
document.querySelectorAll<HTMLImageElement>(".preload");
document.querySelectorAll<HTMLImageElement>(".placeholder");
for (const image of preloadImages) {
image.onload = () => {
console.log("loaded");
image.style.setProperty("--placeholder", null);
};
}
Expand Down

0 comments on commit bed123c

Please sign in to comment.