From 829362b02f139575c89a8e025482b9ff9e1e3c4e Mon Sep 17 00:00:00 2001 From: Manuel Roth Date: Mon, 9 Aug 2021 15:17:37 +0200 Subject: [PATCH 1/7] Preload previous, current and next image and calculate aspect-ratio dynamially based on current image --- views/components/ScrollContainer.svelte | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/views/components/ScrollContainer.svelte b/views/components/ScrollContainer.svelte index c3daff7..8fbcc2f 100644 --- a/views/components/ScrollContainer.svelte +++ b/views/components/ScrollContainer.svelte @@ -27,8 +27,8 @@ $: maxHeight = 2 * containerWidth; $: variant = containerWidth < 500 ? "small" : "large"; - let index, - offset, + let index = 0; + let offset, progress, windowHeight, top, @@ -38,7 +38,7 @@ paddingBottom; $: { - aspectRatio = images[0].width / images[0].height; + aspectRatio = images[index].width / images[index].height; imageHeight = containerWidth / aspectRatio; if (variant === "small") { // set 90px distance to top on mobile @@ -92,7 +92,7 @@ => smooth transition n to n+1 --> {#each imageUrlsReverse as { id, image }} - {#if [index, index + 1].includes(id)} + {#if [index - 1, index, index + 1].includes(id)} windowHeight - top} + class:image--hidden={[index - 1, index + 1].includes(id)} src={image.png1x} alt="" transition:fade={{ duration: 50 }} @@ -143,4 +144,8 @@ left: 50%; transform: translate(-50%, 0); } + + .image--hidden { + visibility: hidden; + } From 7187478d5bd9eab64045fe23d2a2d06951dfb040 Mon Sep 17 00:00:00 2001 From: Manuel Roth Date: Tue, 10 Aug 2021 14:02:38 +0200 Subject: [PATCH 2/7] Better handle case when no variant was found --- views/components/ScrollContainer.svelte | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/views/components/ScrollContainer.svelte b/views/components/ScrollContainer.svelte index 8fbcc2f..74b85b4 100644 --- a/views/components/ScrollContainer.svelte +++ b/views/components/ScrollContainer.svelte @@ -21,7 +21,11 @@ .sort((a, b) => b.minWidth - a.minWidth) .find((variant) => containerWidth >= variant.minWidth); - return variant.asset; + if (variant && variant.asset) { + return variant.asset; + } else { + return {}; + } }); $: maxHeight = 2 * containerWidth; @@ -63,9 +67,11 @@ } } - $: imageUrls = images.map((image) => - getImageUrls(image, containerWidth, imageServiceUrl) - ); + $: imageUrls = images.map((image) => { + if (image && image.key) { + return getImageUrls(image, containerWidth, imageServiceUrl); + } + }); $: imageUrlsReverse = imageUrls.map((image, id) => ({ id, image })).reverse(); @@ -92,7 +98,7 @@ => smooth transition n to n+1 --> {#each imageUrlsReverse as { id, image }} - {#if [index - 1, index, index + 1].includes(id)} + {#if image && [index - 1, index, index + 1].includes(id)} Date: Tue, 10 Aug 2021 14:51:39 +0200 Subject: [PATCH 3/7] Move footer out of background --- views/ScrollGraphic.svelte | 2 ++ views/components/ScrollContainer.svelte | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/views/ScrollGraphic.svelte b/views/ScrollGraphic.svelte index 0eb1695..69edb67 100644 --- a/views/ScrollGraphic.svelte +++ b/views/ScrollGraphic.svelte @@ -1,5 +1,6 @@