An image that zooms in where the pointer is, on hover or on click.
Installation
Usage
<script setup lang="ts">
import { Image, ImageZoom } from '@animate-ui/vue/primitives/effects/image-zoom';
</script>
<template>
<ImageZoom width="320px" height="320px" aria-label="Product photo, zoomable">
<Image src="/product.webp" alt="The product" />
</ImageZoom>
</template>Image renders an img by default; pass as to use your framework's image component (:as="NuxtImg").
Animation
- Hovering zooms in to
zoom-scaleon a spring, from the point under the pointer; moving the pointer pans the zoom. - Clicking (or tapping on touch screens) toggles the zoom. The cursor shows whether a click zooms in or out.
- Under reduced motion, the zoom jumps instead of scaling.
API Reference
ImageZoom
| Prop | Type | Default |
|---|---|---|
zoom-scale? | number | 3 |
transition? | Transition | { type: 'spring', stiffness: 200, damping: 28 } |
zoom-on-hover? | boolean | true |
zoom-on-click? | boolean | true |
disabled? | boolean | false |
width? | string | '100%' |
height? | string | '100%' |
#default | slot | - |
...props? | HTMLAttributes | - |
Image
| Prop | Type | Default |
|---|---|---|
object-fit? | string | 'cover' |
as? | string | Component | 'img' |
...props? | HTMLAttributes | - |
Credits
- Inspired by Jurre's Hover Zoom Framer component.