# pan-zoom-control

> ## 概览

Latest version **1.0.1** (published 2024-09-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install pan-zoom-control
pnpm add pan-zoom-control
yarn add pan-zoom-control
bun add pan-zoom-control
```

## 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 | 1.0.1 |
| Published | 2024-09-09 |
| First published | 2024-04-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 7.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Young |
| Maintainers | young-3303 |
| Keywords | zoom, drag, typescript, control, ui |

## Links

- npm: https://www.npmjs.com/package/pan-zoom-control
- Homepage: https://github.com/young-3303/PanZoomControl.git
- npm.io page: https://npm.io/package/pan-zoom-control

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2024-09-09
- 1.0.0 — 2024-04-19
- 0.0.9 — 2024-04-17
- 0.0.8 — 2024-04-17
- 0.0.7 — 2024-04-16
- 0.0.6 — 2024-04-16
- 0.0.5 — 2024-04-15
- 0.0.4 — 2024-04-12
- 0.0.3 — 2024-04-12
- 0.0.2 — 2024-04-12
- 0.0.1 — 2024-04-12
- 0.0.0 — 2024-04-12

## README

# PanZoomControl

## 概览

由于最近工作开发需要，故开发了一个可以将 HTML 元素变为可缩放和可拖动对象工具类，就像我们平时对图像进行缩放、拖动一样

## 特点

- 使用鼠标滚轮进行平滑缩放，以光标为中心。
- 可拖动功能，允许使用鼠标移动元素。
- 自动边界限制，在缩放和拖动时保持元素在其容器内。

## 示例

![image](https://github.com/young-3303/PanZoomControl/blob/main/public/gif/example.gif?raw=true)

## 使用方式
``` bash
npm i pan-zoom-control --save
```
``` typescript
import PanZoomControl from 'PanZoomControl';

document.addEventListener('DOMContentLoaded', () => {
  const mydiv = document.getElementById('mydiv') as HTMLElement;
  const container = document.getElementById('container') as HTMLElement;

  const zoomDrag = new PanZoomControl({
    scaleElement: mydiv;
    container: container;
    maximum: 0.2;
    minimum: 6;
    deltaScale: 0.2
  });
  // 现在 `mydiv` 可在 `container` 内缩放和拖动。

  // 之后清理：
  // zoomDrag.destroy();
});
```



#### options参数

| 参数       | 说明                               | 类型          | 默认值 |
| ---------- | ---------------------------------- | ------------- | :----: |
| element    | 应用缩放和拖动功能的 HTML 元素。   | `HTMLElement` |        |
| container  | 限制目标元素缩放和拖动的容器元素。 | `HTMLElement` |        |
| maximum    | 最大缩放比例                       | number        |        |
| minimum    | 最小缩放比例                       | number        |        |
| deltaScale | 缩放灵敏度                         | number        |  0.1   |

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