- Notifications
You must be signed in to change notification settings - Fork44
🔍 React image zoom component
License
NotificationsYou must be signed in to change notification settings
samuelmeuli/react-magnifier
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
React image zoom component
- Simple and customizable
- Supports touch screens
- Allows different files for large image and magnifying glass (e.g. thumbnail and high-resolution image)
→Demo
Install the package using NPM:
npm install react-magnifierAdd the component to your React application:
importMagnifierfrom"react-magnifier";importyourImagefrom"./path/to/image";exportdefaultfunctionExampleComponent(){return<Magnifiersrc={yourImage}width={500}/>;}
| Prop | Type | Default | Description |
|---|---|---|---|
src (required) | String | – | URL/path of the large image |
height | Number/String | 'auto' | Image height (absolute or relative values possible) |
width | Number/String | '100%' | Image width (absolute or relative values possible) |
className | String | '' | Class which will be applied to the image wrapper |
zoomImgSrc | String | – | URL/path of the image inside the magnifying glass (if not specified, the large image will be used) |
zoomFactor | Number | 1.5 | Factor by which the zoom image will be scaled (based on the size of the large image) |
mgWidth | Number | 150 | Width of the magnifying glass in px |
mgHeight | Number | 150 | Height of the magnifying glass in px |
mgBorderWidth | Number | 2 | Border width of the magnifying glass in px |
mgShape | String | 'circle' | Shape of the magnifying glass (possible values:'circle','square') |
mgShowOverflow | Boolean | true | Set this tofalse to cut off the magnifying glass at the image borders. When disablingmgShowOverflow, it's recommended that you also set all offsets to0 |
mgMouseOffsetX | Number | 0 | Horizontal offset of the magnifying glass in px when hovering with a mouse |
mgMouseOffsetY | Number | 0 | Vertical offset of the magnifying glass in px when hovering with a mouse |
mgTouchOffsetX | Number | -50 | Horizontal offset of the magnifying glass in px when dragging on a touch screen |
mgTouchOffsetY | Number | -50 | Vertical offset of the magnifying glass in px when dragging on a touch screen |
Any other props will be passed down to the<img> element. This way, you can e.g. add analt attribute to the image.
.magnifier {/* Styles for <div> around image and magnifying glass */}.magnifier-image {/* Styles for large image */}.magnifying-glass {/* Styles for magnifying glass */}
Requirements: Node.js, Yarn
- Clone this repository:
git clone [repo-url] - Install all dependencies:
yarn install - Run
yarn startto generate the library bundle usingRollup and see the component in action usingStorybook
Suggestions and contributions are always welcome! Please first discuss changes via issue before submitting a pull request.
About
🔍 React image zoom component
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
No packages published
Contributors4
Uh oh!
There was an error while loading.Please reload this page.
