mrkeyoor.comAsk

npm package

medium-zoom review

Use medium-zoom 1.1.2 for selected article images when your page can own keyboard entry, layering and content cleanup.

npmWeb Frontendupdated 23 Nov 2026

A screenshot can fit your article and still be too small to read. medium-zoom is a JavaScript library for zooming images. It adds click-to-enlarge behavior to selected images, with an overlay, an optional higher-resolution source and methods for opening or closing the view. The integration decision is whether your page can own image selection, keyboard entry and cleanup when content changes. These examples describe version 1.1.2. They are source-based illustrations and have not been executed for this guide.

Verdict

Use medium-zoom 1.1.2 for selected article images when your page can own keyboard entry, layering and content cleanup. During teardown, wait for an active view's closed event before detaching images or removing their DOM. Evaluate PhotoSwipe for a gallery or basicLightbox for mixed content, and verify the chosen interaction on your page before shipping.

Answers from our run

medium-zoom or photoswipe: which should you use?

photoswipe: Consider PhotoSwipe for an image gallery and lightbox. Its version 5 README identifies that scope; evaluate the gallery behavior your page requires before choosing it. Use medium-zoom 1.1.2 for selected article images when your page can own keyboard entry, layering and content cleanup.

When should you not use medium-zoom?

The requirement is a browsable photo gallery with next and previous controls. The supplied medium-zoom API documents opening a selected image, without documenting gallery navigation controls.

API stability4/5The pinned README defines selectors, options, promise-returning open and close methods, attachment methods and named events. The supplied implementation exposes that surface, but a repeated close() call can resolve before an existing closure finishes. This is a documentation and source assessment, not evidence of compatibility with every framework or integration.
Docs4/5The version-matched README covers selector types, option defaults, methods, events, a high-resolution image attribute and the pure build. It also explains the host page's z-index decision. The supplied implementation adds an important teardown qualification: callers must coordinate through closed when closure is already underway. Complete focus handling remains application work.
Maintenance3/5The supplied changelog dates 1.1.2 to October 25, 2026 and lists fixes for closing during loading, reduced motion, mobile pinch zoom and stylesheet side effects. It records 1.1.1 on that date after 1.1.0 in November 2023. This documents release activity and a release gap; it does not establish a regular update cadence or maintainer response time.
Ecosystem3/5The version-specific npm manifest provides a main entry, an ES module entry and bundled type declarations. The pinned README lists React, Vue and Svelte integration starting points alongside a DOM API. These are documented integration options. No supplied measurements establish adoption, framework compatibility or the completeness of those integrations.

Use it if

Your article or documentation page needs readers to inspect a screenshot without leaving the page.
You can mark the images that deserve zoom and provide a larger image file when the thumbnail is too small.
Your app can attach images after rendering and wait for an active view to finish closing before removing its content.
You want to control image zoom from an ordinary button while keeping the surrounding UI in your own code.

Skip it if

The requirement is a browsable photo gallery with next and previous controls. The supplied medium-zoom API documents opening a selected image, without documenting gallery navigation controls.
You need a finished accessible dialog. The supplied implementation handles Escape dismissal, but keyboard entry and a complete focus policy remain application work.
You want to create the viewer on the server. Creating a zoom instance accesses window and document, so initialize it in browser code after its images exist.
Your policy forbids inline styling. The pure build separates the stylesheet, but the viewer still writes styles such as image transforms at runtime.

Setup reality

Install the reviewed release with npm install medium-zoom@1.1.2. Its npm manifest points the main entry at dist/medium-zoom.min.js, the module entry at dist/medium-zoom.esm.js and the types entry at dist/medium-zoom.d.ts. The manifest's gitHead matches the supplied source commit. The normal import includes the styles. For an explicit stylesheet import, use medium-zoom/dist/pure together with medium-zoom/dist/style.css in a bundler that handles CSS imports. Create the instance in browser code after the target images exist.

A selector attaches the images present when it runs. It does not subscribe to future article renders. Keep the returned instance and attach newly rendered images yourself. Before removing an article, stop its own zoom triggers and wait for any active view to emit closed. Register that completion listener before requesting closure. Awaiting zoom.close() alone is insufficient when another action has already started closing: the supplied implementation immediately resolves a second close() call while the original transition can still be running. The teardown example below waits for closed whether closure starts there or was already initiated by Escape, scrolling or clicking.

Remove callbacks registered through on with off while their images are still attached, then detach the images. The implementation removes its document click listener when the attached image list becomes empty. Its temporary keyboard, scroll, touch and resize listeners are removed when closing finishes. Remove your own button handlers too, and prevent new openings during teardown.

The README leaves z-index to the host page. Choose a level that works with your navigation and dialogs, then inspect both the overlay and the opened image. data-zoom-src loads a larger file when the image opens, so check a slow request and a broken URL. Version 1.1.2 fixes closing during loading or opening, honors reduced-motion preferences and keeps images open during mobile pinch zoom, according to its release notes. These are upstream release claims, not results measured for this guide.

A focusable button that calls open gives keyboard users a way in. It does not finish focus handling, accessible names or dismissal testing. Before shipping, check entry and return focus, Escape, scrolling, reduced motion and route changes on your page. No installation, browser behavior, rendered layout, compatibility, security or performance tests were performed for this guide. No sandbox measurements were supplied.

Reader scores follow the site's published rubric, computed in code. The dimension notes below describe the editor's assessment of the supplied documentation, implementation and release history. They do not establish measured reliability, adoption or framework compatibility. No separate five-point editorial scale is assigned here.

Patterns

Pin the release used in these examples install-reviewed-version

npm install medium-zoom@1.1.2

Documentation-based illustration, not an executed installation. The version-specific npm manifest identifies 1.1.2 and the inspected source commit. Your lockfile and browser checks still belong to your application.

Attach only marked article images select-article-images

import mediumZoom from 'medium-zoom';

// Run after the article renders in the browser.
const zoom = mediumZoom('article img[data-zoomable]');

Add data-zoomable to the intended img elements. The selector captures the images currently present, so newly rendered content needs another attach call.

Leave space around the enlarged image set-view-options

import mediumZoom from 'medium-zoom';

const zoom = mediumZoom('article img[data-zoomable]', {
  margin: 24,
  background: '#111827',
  scrollOffset: 80,
});

These values are application choices. scrollOffset is the scroll distance used to dismiss the view, not an animation duration. Setting it to zero does not disable scroll dismissal in the supplied implementation.

Keep a readable image behind the thumbnail provide-large-source

<img
  data-zoomable
  src="/images/settings-small.jpg"
  data-zoom-src="/images/settings-large.jpg"
  alt="Settings panel showing notification preferences"
/>

Initialize the selector after this markup exists. These image paths are illustrative and must be replaced with your files. The larger file loads on zoom; check slow or failed loading separately.

Import CSS explicitly with the pure build import-separate-styles

import mediumZoom from 'medium-zoom/dist/pure';
import 'medium-zoom/dist/style.css';

const zoom = mediumZoom('article img[data-zoomable]');

Use a bundler that handles CSS imports. Separating the stylesheet does not eliminate runtime style writes, so this does not establish compatibility with a policy that forbids inline styles.

Register images after a content update attach-inserted-images

// zoom is the existing instance. Call after new DOM content is inserted.
const nextImages = document.querySelectorAll('article img[data-zoomable]');
zoom.attach(nextImages);

attach filters images already in its image list. This explicit step is needed because the supplied instance implementation has no DOM observer. Remove obsolete images separately.

Give an image a keyboard-accessible trigger open-from-button

import mediumZoom from 'medium-zoom';

const image = document.querySelector('#diagram');
const button = document.querySelector('#enlarge-diagram');
if (image && button) {
  const zoom = mediumZoom(image);
  const openDiagram = () => zoom.open({ target: image });
  button.addEventListener('click', openDiagram);
  // Before teardown, remove this same callback:
  // button.removeEventListener('click', openDiagram);
}

Provide an img with id="diagram" and a button with id="enlarge-diagram", type="button" and a visible label. The button supplies keyboard entry. This excerpt does not implement a complete dialog focus policy. Retain the callback and instance in your component's lifecycle so teardown can remove the handler and release the zoom.

Distinguish starting from finishing the opening observe-completed-open

function onOpened(event) {
  console.log('Finished opening:', event.target.alt);
}

zoom.on('opened', onOpened);
// Later, while the images are still attached:
zoom.off('opened', onOpened);

This demonstrates registration and removal, not an analytics counter. open fires at the start. opened follows completion, and cancelling an opening can resolve open() without emitting opened.

Wait for closure before releasing an article close-before-removal

function waitUntilClosed(zoom) {
  if (!zoom.getZoomedImage()) {
    return Promise.resolve();
  }

  return new Promise(resolve => {
    function onClosed() {
      zoom.off('closed', onClosed);
      resolve();
    }

    zoom.on('closed', onClosed);
    zoom.close();
  });
}

async function releaseArticleZoom(zoom, removeOwnHandlers) {
  // Stop this article's buttons and other application zoom triggers.
  removeOwnHandlers();
  await waitUntilClosed(zoom);
  zoom.detach();
}

// Await releaseArticleZoom(zoom, removeOwnHandlers)
// before removing the article DOM.

Unexecuted source-based illustration. Keep the images attached until closed so the completion listener can run. getZoomedImage() remains non-null during closing in the supplied implementation. Registering the listener before calling close() covers a view already closing through Escape, scrolling or clicking, as well as closure requested here. A repeated close() promise alone does not wait for that earlier closure. Supply removeOwnHandlers to stop your triggers and remove your registered callbacks with off; retain no callback that can reopen the viewer during teardown. Call this teardown once for the departing article.

Place the overlay above your page chrome fix-layer-order

.medium-zoom-overlay,
.medium-zoom-image--opened {
  z-index: 1000;
}

The README leaves z-index unspecified. This value is an example. Reconcile it with your header and modal layers and inspect the result on your page.

Change settings on an existing instance update-view-options

zoom.update({
  background: '#ffffff',
  margin: 32,
});

update changes the instance options and emits update on its attached images. It does not attach new images. The supplied update implementation changes the overlay background directly but does not invoke the opening layout calculation, so set layout options before the next opening.

Alternatives

PackageRegistryPick it when
photoswipenpmConsider PhotoSwipe for an image gallery and lightbox. Its version 5 README identifies that scope; evaluate the gallery behavior your page requires before choosing it.
basiclightboxnpmConsider basicLightbox when the overlay must contain videos, iframes or arbitrary HTML. Its README explicitly documents those content types.

More web frontend guides

How this guide is made: grounded in the library's documentation, release notes, changelog, and issue history, on a fixed rubric — not a hands-on install of every release. The 50 most-downloaded entries are additionally install-verified in clean containers. Corrections: contact the desk.