A reusable image gallery component with hover-based image switching. When multiple images are provided, the component divides the image area into invisible vertical zones - hovering over each zone displays the corresponding image, similar to Instagram or Tinder photo galleries.
When a single image is provided, the component renders it without gallery functionality.
---
import { ImageGallery } from '@yatoday/astro-ui/astro';
---
<div class="w-64 h-48 overflow-hidden">
<ImageGallery
image={{src: '/images/photo.jpg', alt: 'Single image'}}
/>
</div>
When an array of images is provided, the component enables gallery mode with hover zones and indicator dots.
---
import { ImageGallery } from '@yatoday/astro-ui/astro';
---
<div class="w-64 h-48 overflow-hidden">
<ImageGallery
image={[
{src: '/images/photo-1.jpg', alt: 'View 1'},
{src: '/images/photo-2.jpg', alt: 'View 2'},
{src: '/images/photo-3.jpg', alt: 'View 3'},
]}
/>
</div>
Enable the hoverEffect prop to add a scale animation on hover (useful when wrapped in a link).
<a href="/product" class="block w-64 h-48 overflow-hidden group">
<ImageGallery
image={[
{src: '/images/photo-1.jpg', alt: 'View 1'},
{src: '/images/photo-2.jpg', alt: 'View 2'},
]}
hoverEffect={true}
/>
</a>
The component supports badge slots for overlaying content on the image.
<ImageGallery
image={[
{src: '/images/photo-1.jpg', alt: 'View 1'},
{src: '/images/photo-2.jpg', alt: 'View 2'},
]}
>
<Fragment slot="badgeBottomRight">
<span class="bg-red-500 text-white text-xs px-2 py-1 rounded">Sale</span>
</Fragment>
<Fragment slot="badgeBottomLeft">
<span class="bg-black/50 text-white text-xs px-2 py-1 rounded">New</span>
</Fragment>
</ImageGallery>
<script>
import { ImageGallery } from '@yatoday/astro-ui/svelte';
</script>
<div class="w-64 h-48 overflow-hidden">
<ImageGallery
image={[
{src: '/images/photo-1.jpg', alt: 'View 1'},
{src: '/images/photo-2.jpg', alt: 'View 2'},
{src: '/images/photo-3.jpg', alt: 'View 3'},
]}
hoverEffect={true}
>
{#snippet badgeBottomRight()}
<span class="bg-red-500 text-white text-xs px-2 py-1 rounded">Sale</span>
{/snippet}
</ImageGallery>
</div>
| Prop | Type | Default | Description |
|---|---|---|---|
image | Image | Image[] | string | - | Single image, array of images for gallery, or HTML string |
imageClass | string | '' | CSS classes for the image element |
imageLayout | string | 'cover' | Image layout mode: fixed, constrained, fullWidth, cover, responsive, contained |
widths | number[] | [400, 900] | Image widths for srcset |
width | number | 400 | Image width |
height | number | 400 | Image height |
sizes | string | '(max-width: 900px) 400px, 900px' | Image sizes attribute |
hoverEffect | boolean | false | Whether to add hover scale effect (requires parent with group class) |
class | string | '' | Additional class for the container |
| Slot | Description |
|---|---|
badgeBottomRight | Content to display at the bottom right of the image |
badgeBottomLeft | Content to display at the bottom left of the image |
This component is used internally by Card1, Card2, Card3, and Card6 components. You can use it directly for custom layouts or when you need more control over the image gallery behavior.
---
import { Card2 } from '@yatoday/astro-ui/astro';
---
<!-- Card2 uses ImageGallery internally -->
<Card2
title="Product"
image={[
{src: '/images/front.jpg', alt: 'Front'},
{src: '/images/back.jpg', alt: 'Back'},
]}
url="/product"
/>