Hook Signature
Return Value
The hook returns an object with the following properties:Function to initialize click-based zoom on a container element. Users click once to zoom in and can move their mouse to pan, then click again to zoom out.
The container element that wraps the image element
Configuration options for the zoom behavior
Reactive state object that tracks the zoomed image status
Loading status of the zoomed image
Options
Magnification factor for the zoomed image. A value of 4 means the image displays at 400% size.
URL of the high-resolution image to display when zoomed. Defaults to the source image’s
src.If
true, allows page scrolling while interacting with the zoomed imageAdditional props for the zoomed image element
Alt text for the zoomed image
Example
User Interaction Flow
- First click: Activates zoom mode and displays the zoomed image at the clicked position
- Move mouse: While zoomed, moving the mouse pans the zoomed image
- Second click: Deactivates zoom and returns to normal view
With Scroll Lock Disabled
By default, page scrolling is disabled when hovering over the zoom area. You can allow scrolling:Status Indicators
You can display loading states based on thezoomedImgStatus:
Container Requirements
For optimal zoom behavior, the container should have:- Fixed dimensions (
heightandwidth) overflow: hiddento contain the zoomed imageposition: relativefor proper image positioning- An appropriate cursor style (e.g.,
cursor: pointerorcursor: zoom-in)
Cleanup
The hook automatically handles cleanup of event listeners, DOM elements, and state subscriptions when the component unmounts. No manual cleanup is required.See Also
- createZoomImageClick - Core API documentation
- useZoomImageMove - Move-based zoom hook
- useZoomImageWheel - Wheel-based zoom hook