0.0.0 • Published 9 months ago

hana-img-viewer v0.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
9 months ago

hana-img-viewer

A lightweight and easy-to-use image previewer for Vue 3.

Features

  • Support touch gestures, drag and pan physical effect sliding, two-finger specified position to zoom in and out
  • Based on typescript, type safe
  • Just like use the <img> tag, you can use the src attribute to specify the image source

Installation

pnpm add hana-img-viewer -D

Basic Usage

1. partial import

You can just import the component where you need it.

<script setup lang="ts">
import { HanaImgViewer } from 'hana-img-viewer'
import demoImg from '../assets/114388636.jpg'
</script>

<template>
  <div class="wrapper">
    <hana-img-viewer :src="demoImg" :alt="demoImg" />
  </div>
</template>

2. global registration

In your Vue3 + TypeScript project, you can register the component globally in the main.ts file.

import { createApp } from 'vue'
import App from './App.vue'
import HanaImgViewer from 'hana-img-viewer'

const app = createApp(App)

app.use(HanaImgViewer)

app.mount('#app')

Then you can use the component in any .vue file.

<script setup lang="ts">
// import { HanaImgViewer } from 'hana-img-viewer' // no need to import
import demoImg from '../assets/114388636.jpg'
</script>

<template>
  <div class="wrapper">
    <hana-img-viewer :src="demoImg" :alt="demoImg" />
  </div>
</template>

Props

以下是提供的所有属性:

PropTypeDefaultDescription
srcstring-必填,图片的 URL。
altstring''图片的替代文本,用于描述图片内容。
widthstring \| numberauto图片的宽度。
heightstring \| numberauto图片的高度。
durationnumber500过渡动画的持续时间(单位:毫秒)。
maskBgColorstring'black'遮罩层的背景颜色。
maskOpacitynumber0.1遮罩层的透明度,范围为 0 ~ 1。
previewZIndexnumber1000预览层的 z-index 值,用于控制层级关系。
previewMaxWidthstring \| number'80vw'图片预览区域的最大宽度。
previewMaxHeightstring \| number'80vh'图片预览区域的最大高度。
zoomStepnumber0.2缩放时的步进值,每次放大或缩小时的比例增量。
zoomMinnumber0.2最小缩放比例。
zoomMaxnumber10最大缩放比例。
dblClickZoombooleantrue是否启用双击放大功能。
dblClickZoomTonumber2双击放大时的目标比例。

License

MIT

0.0.0

9 months ago

1.0.3

9 months ago

1.0.2

9 months ago

1.0.1

9 months ago

1.0.0

9 months ago