Inner Image Zoom
- Package
inner-image-zoom
- Source code
Open repo on GitHub
- Changelog
Open changelog on GitHub
Quickstart
1
Install
npm install inner-image-zoom
2
Import
import InnerImageZoom from 'inner-image-zoom';
3
Style
import 'inner-image-zoom/lib/styles.min.css'
4
Initialize
new InnerImageZoom()
5
Template
<img class="iiz" src="/path/to/image.jpg" />
Installation
NPM
Yarn
CDN
TypeScript
Type declarations were added with version 1.0.0.
Styling
You can download the raw styles.css file or, if your build supports it, import the stylesheet directly from node_modules
using:
Usage
HTML
Initializing Inner Image Zoom requires an img
tag and selector (either custom or the default iiz
). The img
tag can be standalone:
Or in a container:
Options may be applied to specific instances using data attributes:
Any content within the container will be preserved. This is useful for responsive images or adding custom image spacers or loading states:
JavaScript
Start by importing and initializing:
You can also initialize with a custom selector or options object:
Options
Name | Type | Default | Description |
---|---|---|---|
zoomSrc | string | URL for the larger zoom image. Falls back to original image src if not defined. | |
zoomScale | number | 1 | Multiplied against the natural width and height of the zoomed image. This will generally be a decimal (example, 0.9 for 90%). |
zoomPreload | boolean | false | If set to true, preloads the zoom image instead of waiting for mouseenter and (unless on a touch device) persists the image on mouseleave. |
moveType | "pan" | "drag" | pan | The user behavior for moving zoomed images on non-touch devices. |
zoomType | "click" | "hover" | click | The user behavior for triggering zoom. When using hover , combine with zoomPreload to avoid flickering on rapid mouse movements. |
fadeDuration | number | 150 | Fade transition time in milliseconds. If zooming in on transparent images, set this to 0 for best results. |
fullscreenOnMobile | boolean | false | Enables fullscreen zoomed image on touch devices below a specified breakpoint. |
mobileBreakpoint | number | 640 | The maximum breakpoint for fullscreen zoom image when fullscreenOnMobile is true. |
hideCloseButton | boolean | false | Hides the close button on touch devices. If set to true, zoom out is triggered by tap. |
hideHint | boolean | false | Hides the magnifying glass hint. |
className | string | Custom classname for styling the component. | |
afterZoomIn | () => void | Function to be called after zoom in. | |
afterZoomOut | () => void | Function to be called after zoom out. |
Methods
reinit
- Reinitialize an InnerImageZoom instance with new options.uninit
- Unitialize an InnerImageZoom instance.