<script>
import { fade } from 'svelte/transition';
import { quintOut } from 'svelte/easing';
let images = $state([
{ id: 1, src: '/images/photo1.jpg', alt: 'Photo 1' },
{ id: 2, src: '/images/photo2.jpg', alt: 'Photo 2' },
{ id: 3, src: '/images/photo3.jpg', alt: 'Photo 3' }
]);
let currentIndex = $state(0);
let current = $derived(images[currentIndex]);
function next() {
currentIndex = (currentIndex + 1) % images.length;
}
function prev() {
currentIndex = (currentIndex - 1 + images.length) % images.length;
}
</script>
<div class="gallery">
<button onclick={prev}>Previous</button>
{#key current.id}
<img
src={current.src}
alt={current.alt}
transition:fade={{ duration: 300, easing: quintOut }}
/>
{/key}
<button onclick={next}>Next</button>
</div>