# zoomist

> A TypeScript library for zooming any element. Also supports mobile devices.

Latest version **2.2.0** (published 2025-03-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install zoomist
pnpm add zoomist
yarn add zoomist
bun add zoomist
```

## Health

**Score 35/100 (D)** — status: maintenance-mode.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.2.0 |
| Published | 2025-03-16 |
| First published | 2021-12-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 76.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 126 |
| Author | Wilson Wu |
| Maintainers | cotton123236 |
| Keywords | image, move, darg, scale, zoom, zoomist, zoomer, zooming, pinch, pinchzoom, gesture, touch, touchzoom, touchmove, mobile, javascript, front-end |

## Links

- npm: https://www.npmjs.com/package/zoomist
- Repository: https://github.com/cotton123236/zoomist
- Homepage: https://github.com/cotton123236/zoomist#readme
- Issues: https://github.com/cotton123236/zoomist/issues
- npm.io page: https://npm.io/package/zoomist

## Alternatives

- [exif-parser](https://npm.io/package/exif-parser.md) — 3.8M weekly downloads
- [vite-plugin-compression](https://npm.io/package/vite-plugin-compression.md) — 569.5K weekly downloads
- [pica](https://npm.io/package/pica.md) — 442.4K weekly downloads
- [@reportportal/client-javascript](https://npm.io/package/@reportportal/client-javascript.md) — 408.8K weekly downloads
- [@tldraw/state](https://npm.io/package/@tldraw/state.md) — 316.0K weekly downloads

## Recent versions

- 2.2.0 (latest) — 2025-03-16
- 2.0.10 (next) — 2023-10-04
- 2.1.1 — 2024-06-15
- 2.1.0 — 2024-06-14
- 2.0.12 — 2024-06-05
- 2.0.11 — 2023-11-01
- 2.0.9 — 2023-10-02
- 2.0.8 — 2023-09-28
- 2.0.7 — 2023-09-28
- 2.0.6 — 2023-09-28
- 2.0.5 — 2023-09-28
- 2.0.4 — 2023-09-27
- 2.0.3 — 2023-09-27
- 2.0.2 — 2023-09-27
- 2.0.1 — 2023-09-27
- … 5 more at https://npm.io/package/zoomist/versions

## README

<div align="center">
  <img src="https://i.imgur.com/fHxO8Fl.png" width="100px" height="100px" alt="logo" />
  <h1>
    <picture>
      <source media="(prefers-color-scheme: dark)" srcset="https://i.imgur.com/jRsv3If.png"/>
      <img src="https://i.imgur.com/QEk2wic.png" width="160"/>
    </picture>
  </h1>
  <p>Zoomist is TypeScript library for zooming any element. Also supports mobile devices.</p>
</div>

<p align="center">
  <a href="https://zoomist.vercel.app/" target="_blank">Documentation</a> | 
  <a href="https://codesandbox.io/p/sandbox/zoomist-demo-4pxlmz" target="_blank">Demo</a>
</p>

<div align="center">
  <a aria-label="NPM version" href="https://github.com/cotton123236/zoomist">
    <img alt="NPM version" src="https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2Fcotton123236%2Fzoomist%2Fmain%2Fpackage.json&query=%24.version&style=for-the-badge&label=NPM&color=black" />
  </a>
</div>

## 🚀 Installation

There are few ways to import Zoomist into your project:

### Install from NPM

You can easily install Zoomist from NPM.

```
npm i zoomist
```

```js
// import Zoomist styles
import 'zoomist/css'
// import Zoomist
import Zoomist from 'zoomist'

// initialize
const zoomist = new Zoomist(...)
```

### Using CDN

There are two ways to include Zoomist by using CDN.

UMD:

```html
<!-- styles -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/zoomist@2/zoomist.css" />

<!-- scripts -->
<script src="https://cdn.jsdelivr.net/npm/zoomist@2/zoomist.umd.js"></script>
<script>
  const zoomist = new Zoomist(...)
</script>
```

ES modules in browser:

```html
<!-- styles -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/zoomist@2/zoomist.css" />

<!-- scripts -->
<script type="module">
  import Zoomist from 'https://cdn.jsdelivr.net/npm/zoomist@2/zoomist.js'

  const zoomist = new Zoomist(...)
</script>
```

### Download assets

Or you can use Zoomist locally by [DOWNLOAD](https://github.com/cotton123236/zoomist/archive/refs/heads/next.zip) assets.

---

## 📝 Basic usage

After downloading Zoomist, there are a few steps to create a Zoomist:

### Add Zoomist HTML layout

You need to add Zoomist layout in your HTML:

```html
<!-- zoomist-container -->
<div class="zoomist-container">
  <!-- zoomist-wrapper is required -->
  <div class="zoomist-wrapper">
    <!-- zoomist-image is required -->
    <div class="zoomist-image">
      <!-- you can add anything you want to zoom here. -->
      <img src="..." />
    </div>
  </div>
</div>
```

### Custom Zoomist styles

You may want to add some custom styles:

```css
.zoomist-container {
  width: 100%;
  max-width: 600px;
}

.zoomist-image {
  width: 100%;
  aspect-ratio: 1;
}

.zoomist-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
}
```

### Initialize Zoomist

Finally, initialize Zoomist in your js file:

```js
const zoomist = new Zoomist('.zoomist-container', {
  // Optional parameters
  maxScale: 4,
  bounds: true,
  // if you need slider
  slider: true,
  // if you need zoomer
  zoomer: true
})
```

---

## 📖 Documentation

### Parameters

All available parameters and initial value:

```js
new Zoomist('.zoomist-container', {
  // set is draggable or not
  draggable: true,
  // set is wheelable or not
  wheelable: true,
  // set is pinchable or not
  pinchable: true,
  // set image stuck on bounds
  bounds: true,
  // the ratio of zooming at one time
  zoomRatio: 0.1,
  // the max scale of zoomist-image (must be number larger then initScale)
  maxScale: 10,
  // the min scale of zoomist-image (must be number smaller then initScale)
  minScale: 1,
  // set initial scale of zoomist-image
  initScale: null,
  // if set to true, enable to release touch events to allow for further page scrolling when .zoomist-image is on bounds.
  dragReleaseOnBounds: false,
  // if set to true, enable to release wheel events to allow for further page scrolling when .zoomist-image is on mixScale or maxScale.
  wheelReleaseOnMinMax: false,
  // elements matched this class will not be dragged.
  disableDraggingClass: '.zoomist-not-draggable',
  // elements matched this class will not be zoomed by mouse wheel.
  disableWheelingClass: '.zoomist-not-wheelable',
  // if set to true, enable to smooth drag
  smooth: false
  // zoomist slider module
  slider: {
    // the css selector string or a element of the slider
    el: null,
    // the direction of the slider 'horizontal' or 'vertical'
    direction: 'horizontal'
  },
  //
  zoomer: {
    // the wrapper of all zoomer buttons
    el: null,
    // the css selector string or a element for in-zoomer
    inEl: null,
    // the css selector string or a element for out-zoomer
    outEl: null,
    // the css selector string or a element for reset-zoomer
    resetEl: null,
    // in zoomer and out zoomer will be disabled when image comes to maximin or minimum
    disabledClass: 'zoomist-zoomer-disabled'
  }
})
```

### Methods

All available methods:

```js
const zoomist = new Zoomist(...)

zoomist.zoom(ratio)
zoomist.zoomTo(ratio)
zoomist.move({ x, y })
zoomist.moveTo({ x, y })
zoomist.slideTo(value)
zoomist.reset()
zoomist.update(options)
zoomist.destroy(cleanStyle)
zoomist.destroySlider()
zoomist.destroyZoomer()
zoomist.destroyModules()

zoomist.on(event, handler)

zoomist.getImageData()
zoomist.getContainerData()
zoomist.getSliderValue()

zoomist.isOnBoundX()
zoomist.isOnBoundY()
zoomist.isOnBoundTop()
zoomist.isOnBoundBottom()
zoomist.isOnBoundLeft()
zoomist.isOnBoundRight()
zoomist.isOnMinScale()
zoomist.isOnMaxScale()
```

### Events

```js
// Using on parameter before initialization.
const zoomist = new Zoomist('.zoomist-container', {
  on: {
    // invoked when zoomist instance ready
    ready(zoomist) {...},
    // invoked when reset methods be used
    reset(zoomist) {...},
    // invoked when image changes it's size
    resize(zoomist) {...},
    // invoked before destroy methods be used
    beforeDestroy(zoomist) {...},
    // invoked after destroy methods be used
    destroy(zoomist) {...},
    // invoked before update methods be used
    beforeUpdate(zoomist) {...},
    // invoked when update methods be used
    update(zoomist) {...},
    // invoked when image is zooming
    zoom(zoomist, scale) {...},
    // invoked when wheeling
    wheel(zoomist, scale, event) {...},
    // invoked when mousedown on wrapper
    dragStart(zoomist, transform, event) {...},
    // invoked when dragging the image
    drag(zoomist, transform, event) {...},
    // invoked when mouseup on wrapper
    dragEnd(zoomist, transform, event) {...},
    // invoked when mousedown on wrapper
    pinchStart(zoomist, scale, event) {...},
    // invoked when pinching the image
    pinch(zoomist, scale, event) {...},
    // invoked when mouseup on wrapper
    pinchEnd(zoomist, scale, event) {...},
    // invoked when mousedown on slider
    slideStart(zoomist, value, event) {...},
    // invoked when sliding the slider
    slide(zoomist, value, event) {...},
    // invoked when mouseup on slider
    slideEnd(zoomist, value, event) {...}
  }
})

// Using on method after initialization.
// For example:
zoomist.on('zoom', (zoomist, scale) => {...})
```

---
_Source: https://npm.io/package/zoomist · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
