• Stars
    star
    151
  • Rank 246,057 (Top 5 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created almost 7 years ago
  • Updated 9 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🔍 React image zoom component

react-magnifier

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

Demo

Usage

Install the package using NPM:

npm install react-magnifier

Add the component to your React application:

import Magnifier from "react-magnifier";
import yourImage from "./path/to/image";

export default function ExampleComponent() {
  return <Magnifier src={yourImage} width={500} />;
}

Configuration

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 to false to cut off the magnifying glass at the image borders. When disabling mgShowOverflow, it's recommended that you also set all offsets to 0
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 an alt attribute to the image.

Custom styling

.magnifier {
  /* Styles for <div> around image and magnifying glass */
}

.magnifier-image {
  /* Styles for large image */
}

.magnifying-glass {
  /* Styles for magnifying glass */
}

Development

Requirements: Node.js, Yarn

  1. Clone this repository: git clone [repo-url]
  2. Install all dependencies: yarn install
  3. Run yarn start to generate the library bundle using Rollup and see the component in action using Storybook

Suggestions and contributions are always welcome! Please first discuss changes via issue before submitting a pull request.

More Repositories

1

mini-diary

📘 Simple and secure journal app
TypeScript
1,031
star
2

glance

🔎 All-in-one Quick Look plugin
Swift
953
star
3

action-electron-builder

:electron: GitHub Action for building and releasing Electron apps
JavaScript
651
star
4

tmignore

🕔 Exclude development files from Time Machine backups
Swift
322
star
5

font-picker

✏️ Font selector component for Google Fonts
TypeScript
171
star
6

font-picker-react

✏️ Font selector component for Google Fonts
TypeScript
152
star
7

action-maven-publish

📦 GitHub Action for automatically publishing Maven packages
JavaScript
101
star
8

lyrics-poster

🎤 Create posters of your favorite artists, written in their lyrics
JavaScript
63
star
9

refind-theme-dark

🎨 A simple, dark theme for rEFInd
54
star
10

action-snapcraft

🐦 GitHub Action for setting up Snapcraft
JavaScript
49
star
11

font-manager

🗂 Manages, downloads and applies Google Fonts for picker components
TypeScript
27
star
12

swift-exec

🚀 Simple process execution with Swift
Swift
16
star
13

draft-js-list-plugin

📝 Better lists for Draft.js
TypeScript
14
star
14

python-wikibase

🤖 Wikibase queries and edits made easy
Python
11
star
15

nbtohtml

📈 Convert Jupyter Notebook files to HTML
Go
9
star
16

github-downloads

⬇️ See the number of downloads next to releases on GitHub
JavaScript
8
star
17

alfred-system-theme

🎨 Alfred themes in style of Apple's macOS apps
7
star
18

react-library-boilerplate

🔨 Create a React component library with no configuration
JavaScript
6
star
19

iconsets.org

🌟 Icon set discovery website for designers
JavaScript
5
star
20

wikibase-api

📦 Wrapper library for the Wikibase API
Python
4
star
21

anonymize-ip

👤 Python library for anonymizing IP addresses
Python
4
star
22

strava-bulk-edit

🏃 Edit multiple Strava activities at once
Go
2
star
23

electron-md-to-pdf

:electron: Convert Markdown to PDF in Electron apps
CSS
2
star
24

hugo-starter-theme

🔨 Boilerplate for building a custom Hugo theme
HTML
2
star
25

samuelmeuli.com

👨‍💻 My personal website
CSS
1
star
26

music-notifications

🎵 Notification service for new releases on iTunes
JavaScript
1
star
27

prettier-config

☑️ My Prettier configuration
JavaScript
1
star
28

react-app-boilerplate

🔨 Create a React application with no configuration
JavaScript
1
star