Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
R

react-medium-image-zoom

> 前端框架
Open source

The original medium.com-inspired image zooming library for React (since 2016)

2.1K stars0 likes2 views
WebsiteGitHub

About

The original medium.com-inspired image zooming library for React (since 2016)

react-medium-image-zoom

The original medium.com-inspired image zooming library for React.

View the storybook examples to see various usages.

Features:

  • ``, including all object-fit values, any object-position, and loading="lazy"
  • <div> and <span> with any background-image, background-size, and background-position
  • <picture> with <source /> and ``
  • <figure> with ``
  • <svg>
  • Custom zoom modal content ()
  • Accessibility:
    • JAWS in Chrome, Edge, and Firefox (Windows)
    • NVDA in Chrome, Edge, and Firefox (Windows)
    • VoiceOver in Safari (macOS, iOS)
    • TalkBack in Chrome (Android)
  • Supports popular tools:
    • Gatsby and gatsby-plugin-image
    • Next.js
  • Zero dependencies

Requirements to know about:

  • <dialog> element (caniuse dialog)
  • ResizeObserver (caniuse ResizeObserver)
  • Package build target is ES2021. If you need to support older environments, run this package through your build system.

Media and Tutorials

  • 2024-08-2024 — React Round Up — "Building a Seamless Image Zoom Feature"
  • Build a React.js Image Zoom Feature with react-medium-image-zoom Library and State Management

Quickstart

bash
npm install --save react-medium-image-zoom
javascript
import React from 'react'
import Zoom from 'react-medium-image-zoom'
import 'react-medium-image-zoom/dist/styles.css'

export const MyImg = () => (
  <Zoom>
    
  </Zoom>
)

API

You can pass these options to either the Uncontrolled (default) or Controlled components.

…

You can pass these options to only the Controlled component.

typescript
export interface ControlledProps {
  // ...same as UncontrolledProps

  // Tell the component whether or not it should be zoomed
  // Default: false
  isZoomed: boolean
}

Basic Usage

Uncontrolled component (default)

Import the component and the CSS, wrap your image with the component, and the component will handle it's own state.

…

Controlled component

Import the Controlled component and the CSS, wrap your image with the component, and then dictate the isZoomed state to the component.

javascript
import React, { useCallback, useState } from 'react'
import { Controlled as ControlledZoom } from 'react-medium-image-zoom'
import 'react-medium-image-zoom/dist/styles.css'

const MyComponent = () => {
  const [isZoomed, setIsZoomed] = useState(false)

  const handleZoomChange = useCallback(shouldZoom => {
    setIsZoomed(shouldZoom)
  }, [])

  return (
    <ControlledZoom isZoomed={isZoomed} onZoomChange={handleZoomChange}>
      
    </ControlledZoom>
  )
}

export default MyComponent

The onZoomChange prop accepts a callback that will receive true or false based on events that occur (like click or scroll events) to assist you in determining when to zoom and unzoom the component.

Styles

You can import the default styles from react-medium-image-zoom/dist/styles.css and override the values from your code, or you can copy the styles.css file and alter it to your liking. The latter is the best option, given rems should be used instead of px to account for different default browser font sizes, and it's hard for a library to guess at what these values should be.

An example of customizing the transition duration, timing function, overlay background color, and unzoom button styles with :focus-visible can be found in this story: https://rpearce.github.io/react-medium-image-zoom/?path=/story/img--custom-modal-styles

Custom zoom modal content

If you want to customize the zoomed modal experience with a caption, form, or other set of components, you can do so by providing a custom component to the ZoomContent prop.

View the live example of custom zoom modal content.

Below is some example code that demonstrates how to use this feature.

…

Migrating From v4 to v5

Here are the prop changes from v4 to be aware of:

  • closeText was renamed to a11yNameButtonUnzoom
  • openText was renamed to a11yNameButtonZoom
  • overlayBgColorStart was removed and is now controlled via the CSS selector [data-rmiz-modal-overlay="hidden"]
  • overlayBgColorEnd was removed and is now controlled via the CSS selector [data-rmiz-modal-overlay="visible"]
  • portalEl was removed, for we are using the <dialog> element now
  • transitionDuration was removed and is now controlled via the CSS selectors [data-rmiz-modal-overlay] and [data-rmiz-modal-img]
  • wrapElement was removed then added back in v5.1.0
  • wrapStyle was removed
  • zoomZindex was removed, for we are using the <dialog> element now

And you can now provide zoomImg props to specify a different image to load when zooming.

Contributors ✨

Thanks goes to these wonderful people (emoji key):


Robert Pearce

⚠️

Cameron Bothner

⚠️

Jeremy Bini


ismay


Rajit Singh


Roberto Saccon


wtfdaemon


Josh Sloat


Aswin


Alex Shelkovskiy


Adrian Bindiu


Kendall Buchanan


Kaycee


Anuj


Ludwig Frank

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

TypeScripthacktoberfestimage-zoommediumprops

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category前端框架
PricingOpen source

> Related tools

R
React
用于构建用户界面的 JavaScript 库
V
Vue.js
渐进式 JavaScript 框架
N
Next.js
基于 React 的全栈 Web 框架