Add rotating images to Shop module
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { getContext } from 'svelte'
|
import { getContext, onMount } from 'svelte'
|
||||||
// Components
|
// Components
|
||||||
import Button from '$components/atoms/Button.svelte'
|
import Button from '$components/atoms/Button.svelte'
|
||||||
import Image from '$components/atoms/Image.svelte'
|
import Image from '$components/atoms/Image.svelte'
|
||||||
@@ -18,20 +18,46 @@
|
|||||||
.sort((a: Location, b: Location) => a.slug.localeCompare(b.slug))
|
.sort((a: Location, b: Location) => a.slug.localeCompare(b.slug))
|
||||||
// Return name only
|
// Return name only
|
||||||
.map((loc: Location) => loc.name)
|
.map((loc: Location) => loc.name)
|
||||||
|
|
||||||
|
|
||||||
|
// Image rotation
|
||||||
|
let imagesLoop: ReturnType<typeof setTimeout>
|
||||||
|
let currentImageIndex = 0
|
||||||
|
|
||||||
|
const incrementCurrentImageIndex = () => {
|
||||||
|
currentImageIndex = currentImageIndex === shop.module_images.length - 1 ? 0 : currentImageIndex + 1
|
||||||
|
imagesLoop = setTimeout(() => requestAnimationFrame(incrementCurrentImageIndex), 3000)
|
||||||
|
}
|
||||||
|
|
||||||
|
onMount(() => {
|
||||||
|
incrementCurrentImageIndex()
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
// Clear rotating words timeout
|
||||||
|
clearTimeout(imagesLoop)
|
||||||
|
}
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="shop shadow-box-dark">
|
<div class="shop shadow-box-dark">
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<div class="shop__image">
|
<div class="shop__images">
|
||||||
<Image
|
{#if shop.module_images}
|
||||||
id={shop.module_image.id}
|
<a href="/shop" sveltekit:noscroll sveltekit:prefetch>
|
||||||
sizeKey="square"
|
{#each shop.module_images as { directus_files_id: { id }, title }, index}
|
||||||
sizes={{
|
<Image
|
||||||
small: { width: 400, height: 400 },
|
class={index === currentImageIndex ? 'is-visible' : null}
|
||||||
large: { width: 800, height: 800 },
|
{id}
|
||||||
}}
|
sizeKey="square"
|
||||||
alt={shop.module_image.title}
|
sizes={{
|
||||||
/>
|
small: { width: 400, height: 400 },
|
||||||
|
large: { width: 800, height: 800 },
|
||||||
|
}}
|
||||||
|
alt={title}
|
||||||
|
/>
|
||||||
|
{/each}
|
||||||
|
</a>
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="shop__content">
|
<div class="shop__content">
|
||||||
|
|||||||
@@ -129,9 +129,11 @@
|
|||||||
enabled
|
enabled
|
||||||
module_title
|
module_title
|
||||||
module_text
|
module_text
|
||||||
module_image {
|
module_images {
|
||||||
id
|
directus_files_id {
|
||||||
title
|
id
|
||||||
|
title
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,11 +17,26 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Image
|
// Images
|
||||||
&__image {
|
&__images {
|
||||||
position: relative;
|
position: relative;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
|
||||||
|
picture {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
opacity: 0;
|
||||||
|
transform: scale3d(1.075, 1.075, 1.075);
|
||||||
|
transition: opacity 0.8s, transform 1.6s var(--ease-quart);
|
||||||
|
|
||||||
|
&.is-visible {
|
||||||
|
opacity: 1;
|
||||||
|
transform: scale3d(1,1,1);
|
||||||
|
}
|
||||||
|
}
|
||||||
img {
|
img {
|
||||||
display: block;
|
display: block;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
|||||||
Reference in New Issue
Block a user