@coddicat/vue-pinch-scroll-zoom

中文文档
4.7.1发布于 2024/06/13MITTypeScriptESM + CJS近 30 天下载 1.7万

Vue component enabling scroll and zoom functionalities for content, leveraging mouse interactions on desktop and two-finger pinch gestures on mobile devices

原始使用文档
文档目录10 节
  1. Important Note
  2. Installation
  3. Usage
  4. Props
  5. Events
  6. Exposed Methods
  7. Update the data
  8. Centralize image content in the visible area
  9. Move image content in the visible area
  10. Zoom image content in the visible area

vue-pinch-scroll-zoom

Vue component that provides content scrolling and zooming using mouse events or two fingers pinch on a mobile devices

Important Note

As of the current version, this component is compatible and fully tested with Vue "^3.2.47". Please ensure that you are using this version of Vue or later for optimal performance and compatibility. We will continue to maintain and update this component to support later versions of Vue as they become available.

example:

Installation

npm i @coddicat/vue-pinch-scroll-zoom

Usage

main.ts:

import '@coddicat/vue-pinch-scroll-zoom/style.css';
<PinchScrollZoom
  ref="zoomer"
  within
  centered
  key-actions
  :width="300"
  :height="400"
  :min-scale="0.3"
  :max-scale="6"
  @scaling="e => onEvent('scaling', e)"
  @startDrag="e => onEvent('startDrag', e)"
  @stopDrag="e => onEvent('stopDrag', e)"
  @dragging="e => onEvent('dragging', e)"
  style="border: 1px solid black"
  :content-width="500"
  :content-height="500"
>
  <img src="https://picsum.photos/500/500" width="500" height="500" />
</PinchScrollZoom>
<script setup lang="ts">
import { ref, reactive } from 'vue';
import PinchScrollZoom, {
  type PinchScrollZoomEmitData,
  type PinchScrollZoomExposed
} from '@coddicat/vue-pinch-scroll-zoom';

const zoomer = ref<PinchScrollZoomExposed>();

function onEvent(name: string, e: PinchScrollZoomEmitData): void {
  state.eventName = name;
  state.eventData = e;
  state.scale = e.scale;
  state.originX = e.originX;
  state.originY = e.originY;
  state.translateX = e.translateX;
  state.translateY = e.translateY;
}

function reset(): void {
  zoomer.value?.setData({
    scale: 1,
    originX: 150,
    originY: 200,
    translateX: -100,
    translateY: -50
  });
}

Props

the following properties don't support the ".async" modifier

namerequireddescriptiondefault
widthyesvisible area width
heightyesvisible area height
content-widthnoshould be defined when content width is different from container width
content-heightnoshould be defined when content height is different from container height
minScalenominimum allowable scaling0.3
maxScalenomaximum allowable scaling5
withinnolimit scrolling of content to its borderstrue
wheelVelocitynozoom velocity when mouse wheel0.001
scalenoscale of the content1
origin-xnotransform-origin-xwidth/2
origin-ynotransform-origin-yheight/2
translate-xnotransform: translateX0
translate-ynotransform: translateY0
throttleDelaynorendering delay (milliseconds)25
draggablenodraggable of/offtrue
centerednocentralize content in visible areafalse
key-actionsnoenable key press events(focused) for zooming and movingfalse
tabindexnotabindex attribute for the visible area0 if keyActions enabled, value is required for key events
key-zoom-velocitynozoom velocity when zooming by key events0.2
key-move-velocitynomove velocity when moving by key events10
key-controlsnoRecords of keyCode and actionsSee PinchScrollZoomDefaultControls ('+', '-', arrows)
translate3dnoToggle between 'translate' and 'translate3d' transformationtrue

Events

the following events are emitted with the argument:

export interface PinchScrollZoomEmitData {
  x: number;
  y: number;
  scale: number;
  originX: number;
  originY: number;
  translateX: number;
  translateY: number;  
}
  • startDrag
  • stopDrag
  • dragging
  • scaling

Exposed Methods

Update the data

.setData(data: PinchScrollZoomSetData);

export interface PinchScrollZoomSetData {
    scale: number;
    originX: number;
    originY: number;
    translateX: number;
    translateY: number;
}

Centralize image content in the visible area

.centralize();

Move image content in the visible area

.manualMove(deltaX: number, deltaY: number);

Zoom image content in the visible area

.manualZoom(factor: number); //factor relative to the current value, so if current scale is 2 and execute .manualZoom(2) the new scale value will be 4

版本与发布记录

@coddicat/vue-pinch-scroll-zoom 共发布 49 个版本,首次发布于 2021/03/20;过去 12 个月发布了 0 个版本。

版本发布日期距今
4.7.1latest2024/06/132 年前
4.7.02024/06/122 年前
4.6.02024/04/202 年前
4.5.02024/04/092 年前
4.4.02024/04/092 年前
4.3.52023/11/282 年前

关于 @coddicat/vue-pinch-scroll-zoom 的常见问题

@coddicat/vue-pinch-scroll-zoom 是什么?

Vue component enabling scroll and zoom functionalities for content, leveraging mouse interactions on desktop and two-finger pinch gestures on mobile devices

如何安装 @coddicat/vue-pinch-scroll-zoom?

在项目目录运行 npm install @coddicat/vue-pinch-scroll-zoom,或使用 pnpm add / yarn add / bun add。

@coddicat/vue-pinch-scroll-zoom 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@coddicat/vue-pinch-scroll-zoom 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@coddicat/vue-pinch-scroll-zoom 可以商用吗?

@coddicat/vue-pinch-scroll-zoom 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@coddicat/vue-pinch-scroll-zoom 的下载量有多少?

根据 npm 官方下载统计,@coddicat/vue-pinch-scroll-zoom 在 2026/10/10 – 2026/11/08 这 30 天内被下载 16,582 次,日均约 553 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@coddicat/vue-pinch-scroll-zoom 还在维护吗?

最新版本 4.7.1 发布于 2024/06/13(2 年前);至今共发布 49 个版本,其中过去 12 个月发布了 0 个;首次发布于 2021/03/20。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。