diff --git a/src/components/HeroCard.astro b/src/components/HeroCard.astro index 2c2fd22..0428de8 100644 --- a/src/components/HeroCard.astro +++ b/src/components/HeroCard.astro @@ -68,7 +68,8 @@ const hasCover = typeof image === "string" ? !!image?.length : !!cover?.src; loader={false} src={cover as ImageMetadata} alt={"cover for " + title} - class="right-0 h-full object-cover object-center rounded-none border-l border-neutral" + class="h-full right-0 object-cover object-center rounded-none border-l border-neutral" + pictureClass="h-full" thumbnail /> diff --git a/src/components/Image.astro b/src/components/Image.astro index 50e8c77..4582c7c 100644 --- a/src/components/Image.astro +++ b/src/components/Image.astro @@ -88,7 +88,7 @@ const sizes = thumbnail pictureAttributes={{ class: `${hash ? "block h-full relative" : ""} ${loader ? "thumb" : ""} ${pictureClass}`, }} - class={`${Astro.props.class} h-full w-full`} + class={`${Astro.props.class} w-full`} widths={sizes.map((size) => size.width)} sizes={sizes .map((size) => `${size.media || "100vw"} ${size.width}px`) diff --git a/src/components/ImageSlider.svelte b/src/components/ImageSlider.svelte index 78fc853..8cbd647 100644 --- a/src/components/ImageSlider.svelte +++ b/src/components/ImageSlider.svelte @@ -8,11 +8,14 @@ let height: number; let loaded = false; - function hide(img: HTMLPictureElement) { + function hide(index: number) { + const img = images[index]; img.classList.remove("active"); } - function show(img: HTMLPictureElement) { + const heightCache = []; + function show(index: number) { + const img = images[index]; img.classList.add("active"); const _img = img.querySelector("img") || img; if (!_img) return; @@ -21,9 +24,12 @@ _img.style.opacity = "1"; }); altText = _img["alt"] ?? _img.getAttribute("alt") ?? ""; - height = _img.getBoundingClientRect().height; + if (heightCache[index]) { + height = heightCache[index]; + } setTimeout(() => { - height = _img.getBoundingClientRect().height; + height = heightCache[index] ?? _img.getBoundingClientRect().height; + heightCache[index] = height; }, 100); } @@ -31,16 +37,16 @@ function setIndex(i: number) { if (i < 0) i = images.length - 1; if (i >= images.length) i = 0; - hide(images[index]); + hide(index); index = i; - show(images[index]); + show(index); } $: if (slot && !images?.length) { images = Array.from(slot.querySelectorAll("picture")); if (images?.length) { - images.forEach(hide); - show(images[index]); + images.forEach((_, i) => hide(i)); + show(index); images[index].onload = () => { loaded = true; height = images[index].getBoundingClientRect().height; @@ -54,29 +60,27 @@