vue3-ciallo-viewer
Version:
168 lines (154 loc) • 4.96 kB
Markdown
[![NPM version][npm-image]][npm-url] [![node version][node-image]][node-url] [![npm download][download-image]][download-url] [![npm license][license-image]][download-url]
**An exquisite vue3 image preview component.**
**Mobile devices support zooming in and out ✔**


[](https://superarilo.github.io/cialloviewer/)
```bash
npm install vue3-ciallo-viewer --save
```
```
<ViewerList :duration="300" :zoomSpeed="0.2" :maxScaleFactor="5">
<img src='./assets/1.jpg' title='image' alt='' />
</ViewerList>
```
* **duration** : `number` (optional)
The duration of the image transition, in milliseconds. Defaults to `400`.
* **zoomSpeed** : `number` (optional)
Controls the speed of zoom interactions. Defaults to `0.2` if not specified.
* **maxScaleFactor** : `number` (optional)
Sets the maximum scale factor for zooming. Defaults to `5`
```
<template>
<div>
<ViewerList :duration="300" :zoomSpeed="0.2" :maxScaleFactor="5">
<div v-for="(item, index) in list" :key="item.id">
<p>
<span>{{ index + 1 }}</span>
<img :src="item.src" alt=""/>
</p>
</div>
</ViewerList>
</div>
</template>
<script setup lang="ts">
import {ref} from 'vue'
import 'vue3-ciallo-viewer/dist/style.css'
import { ViewerList } from 'vue3-ciallo-viewer'
const list = ref<any[]>([
{
id: 0,
src: 'images/1.jpg'
},
{
id: 1,
src: 'images/2.jpg'
},
{
id: 2,
src: 'images/3.jpg'
}
])
</script>
<style>
img {
height: 128px;
width: 128px;
}
</style>
```
```
CialloViewer(
array: HTMLCollection,
targetIndex?: number | null,
duration: number,
zoomSpeed: number,
maxScaleFactor: number)
```
```
CialloViewer({
array: HTMLCollection,
targetIndex: number | null,
duration: number,
zoomSpeed: number,
maxScaleFactor: number
})
```
* **array** : `HTMLCollection`
The collection of images to display.
* **targetIndex** : `number | null` (optional)
The index of the image to highlight, defaults to `0`.
* **duration** : `number` (optional)
The duration of the image transition, in milliseconds. Defaults to `400`.
* **zoomSpeed** : `number` (optional)
Controls the speed of zoom interactions. Defaults to `0.2` if not specified.
* **maxScaleFactor** : `number` (optional)
Sets the maximum scale factor for zooming. Defaults to `5`
```
<template>
<div>
<div ref="images">
<img class="image_class" v-for="(item, index) in list" :key="item.id" @click="handleClick(index)" :src="item.src" alt=""/>
</div>
</div>
</template>
<script setup lang="ts">
import {CialloViewer} from "vue3-ciallo-viewer"
import 'vue3-ciallo-viewer/dist/style.css'
import {ref} from 'vue'
const list = ref<any[]>([
{
id: 0,
src: './src/assets/images/1.jpg'
},
{
id: 1,
src: './src/assets/images/2.jpg'
},
{
id: 2,
src: './src/assets/images/3.jpg'
}
])
const images = ref<HTMLElement>()
const handleClick = (index: number): void => {
if(!images.value) return
// Deprecated
CialloViewer(images.value.getElementsByTagName('img'), index, 400, 0.2, 5)
// or
CialloViewer({
array: images.value.getElementsByTagName('img'),
targetIndex: index,
duration: 400,
zoomSpeed: 0.2,
maxScaleFactor: 10
})
}
</script>
```
[]: https://img.shields.io/npm/v/vue3-ciallo-viewer.svg?style=flat-square
[]: https://npmjs.org/package/vue3-ciallo-viewer
[]: https://img.shields.io/travis/vue3-ciallo-viewer.svg?style=flat-square
[]: https://travis-ci.org/vue3-ciallo-viewer
[]: https://img.shields.io/coveralls/vue3-ciallo-viewer.svg?style=flat-square
[]: https://coveralls.io/r/vue3-ciallo-viewer?branch=master
[]: https://img.shields.io/david/vue3-ciallo-viewer.svg?style=flat-square
[]: https://david-dm.org/vue3-ciallo-viewer
[]: https://img.shields.io/badge/node.js-%3E=_19-green.svg?style=flat-square
[]: http://nodejs.org/download/
[]: https://img.shields.io/npm/d18m/vue3-ciallo-viewer
[]: https://npmjs.org/package/vue3-ciallo-viewer
[]: https://img.shields.io/npm/l/vue3-ciallo-viewer.svg