Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/components/mdx/BasicImage.astro
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ const isImageMetadata = typeof imageSrc !== "string" && "src" in imageSrc;
animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

.image-wrapper.loaded::before {
animation: none;
}

@keyframes pulse {
0%,
100% {
Expand Down Expand Up @@ -168,3 +172,16 @@ const isImageMetadata = typeof imageSrc !== "string" && "src" in imageSrc;
}
}
</style>

<script>
document.querySelectorAll<HTMLElement>(".image-wrapper").forEach((wrapper) => {
const img = wrapper.querySelector("img");
if (!img) return;
const stopPulse = () => wrapper.classList.add("loaded");
if (img.complete) {
stopPulse();
} else {
img.addEventListener("load", stopPulse, { once: true });
}
});
</script>