Installation
Available Functions
The Svelte adapter exports four functions, one for each zoom mode:useZoomImageWheel- Zoom with mouse wheel/pinch gesturesuseZoomImageHover- Zoom on hover with a separate zoom targetuseZoomImageMove- Zoom follows mouse/touch movementuseZoomImageClick- Toggle zoom on click
Function Return Values
Each function returns an object with:createZoomImage- Function to initialize zoom on a container elementzoomImageState- Svelte store containing state (varies by zoom mode)setZoomImageState- Function to update state (available for wheel and hover modes)
Wheel Zoom
Zoom in and out using the mouse wheel or pinch gestures. Supports programmatic zoom control, rotation, and image cropping.Basic Example
Complete Example with Controls
State Properties
currentZoom: number- Current zoom level (1 = 100%)enable: boolean- Whether zoom is enabledcurrentPositionX: number- X position offsetcurrentPositionY: number- Y position offsetcurrentRotation: number- Rotation angle in degrees
Hover Zoom
Display a zoomed version in a separate container when hovering over the image.Basic Example
State Properties
enabled: boolean- Whether hover is activezoomedImgStatus: string- Loading status (“idle” | “loading” | “loaded”)
Move Zoom
Zoom follows the mouse or touch movement within the image container.Basic Example
State Properties
zoomedImgStatus: string- Loading status (“idle” | “loading” | “loaded”)
Click Zoom
Toggle between zoomed and normal states by clicking the image.Basic Example
State Properties
zoomedImgStatus: string- Loading status (“idle” | “loading” | “loaded”)
TypeScript Support
All functions are fully typed. Import types from@zoom-image/core:
Svelte Stores
ThezoomImageState returned by each function is a Svelte writable store. You can use it with the $ syntax or subscribe to it:
Cleanup
All functions automatically clean up on component destroy using Svelte’sonDestroy lifecycle function.
Framework Compatibility
This adapter works with:- Svelte 3.x
- Svelte 4.x
- Svelte 5.x