# Viewer.js
[![Build Status](https://travis-ci.org/fengyuanchen/viewerjs.svg)](https://travis-ci.org/fengyuanchen/viewerjs) [![Downloads](https://img.shields.io/npm/dm/viewerjs.svg)](https://www.npmjs.com/package/viewerjs) [![Version](https://img.shields.io/npm/v/viewerjs.svg)](https://www.npmjs.com/package/viewerjs) [![Donate on Patreon](https://img.shields.io/badge/donate-on%20patreon-fa7664.svg)](https://www.patreon.com/chenfengyuan)
> JavaScript image viewer.
- [Website](https://fengyuanchen.github.io/viewerjs)
- [jquery-viewer](https://github.com/fengyuanchen/jquery-viewer) - A jQuery plugin wrapper for Viewer.js.
## Table of contents
- [Features](#features)
- [Main](#main)
- [Getting started](#getting-started)
- [Keyboard support](#keyboard-support)
- [Options](#options)
- [Methods](#methods)
- [Events](#events)
- [No conflict](#no-conflict)
- [Browser support](#browser-support)
- [Contributing](#contributing)
- [Versioning](#versioning)
- [License](#license)
## Features
- Supports 39 [options](#options)
- Supports 23 [methods](#methods)
- Supports 9 [events](#events)
- Supports modal and inline modes
- Supports touch
- Supports move
- Supports zoom
- Supports rotation
- Supports scale (flip)
- Supports keyboard
- Cross-browser support
## Main
```text
dist/
├── viewer.css
├── viewer.min.css (compressed)
├── viewer.js (UMD)
├── viewer.min.js (UMD, compressed)
├── viewer.common.js (CommonJS, default)
└── viewer.esm.js (ES Module)
```
## Getting started
### Installation
```shell
npm install viewerjs
```
In browser:
```html
<link href="/path/to/viewer.css" rel="stylesheet">
<script src="/path/to/viewer.js"></script>
```
The [cdnjs](https://github.com/cdnjs/cdnjs) provides CDN support for Viewer.js's CSS and JavaScript. You can find the links [here](https://cdnjs.com/libraries/viewerjs).
### Usage
#### Syntax
```js
new Viewer(element[, options])
```
- **element**
- Type: `HTMLElement`
- The target image or container of images for viewing.
- **options** (optional)
- Type: `Object`
- The options for viewing. Check out the available [options](#options).
#### Example
```html
<!-- a block container is required -->
<div>
<img id="image" src="picture.jpg" alt="Picture">
</div>
<div>
<ul id="images">
<li><img src="picture-1.jpg" alt="Picture 1"></li>
<li><img src="picture-2.jpg" alt="Picture 2"></li>
<li><img src="picture-3.jpg" alt="Picture 3"></li>
</ul>
</div>
```
```js
// import 'viewerjs/dist/viewer.css';
import Viewer from 'viewerjs';
// View an image
const viewer = new Viewer(document.getElementById('image'), {
inline: true,
viewed() {
viewer.zoomTo(1);
},
});
// View a list of images
const gallery = new Viewer(document.getElementById('images'));
```
## Keyboard support
> Only available in modal mode.
- `Esc`: Exit full screen or close the viewer or exit modal mode or stop play.
- `Space`: Stop play.
- `←`: View the previous image.
- `→`: View the next image.
- `↑`: Zoom in the image.
- `↓`: Zoom out the image.
- `Ctrl + 0`: Zoom out to initial size.
- `Ctrl + 1`: Zoom in to natural size.
[⬆ back to top](#table-of-contents)
## Options
You may set viewer options with `new Viewer(image, options)`.
If you want to change the global default options, You may use `Viewer.setDefaults(options)`.
### backdrop
- Type: `Boolean` or `String`
- Default: `true`
Enable a modal backdrop, specify `static` for a backdrop which doesn't close the modal on click.
### button
- Type: `Boolean`
- Default: `true`
Show the button on the top-right of the viewer.
### navbar
- Type: `Boolean` or `Number`
- Default: `true`
- Options:
- `0` or `false`: hide the navbar
- `1` or `true`: show the navbar
- `2`: show the navbar only when the screen width is greater than 768 pixels
- `3`: show the navbar only when the screen width is greater than 992 pixels
- `4`: show the navbar only when the screen width is greater than 1200 pixels
Specify the visibility of the navbar.
### title
- Type: `Boolean` or `Number` or `Function` or `Array`
- Default: `true`
- Options:
- `0` or `false`: hide the title
- `1` or `true` or `Function` or `Array`: show the title
- `2`: show the title only when the screen width is greater than 768 pixels
- `3`: show the title only when the screen width is greater than 992 pixels
- `4`: show the title only when the screen width is greater than 1200 pixels
- `Function`: customize the title content
- `[Number, Function]`: the first element indicate the visibility, the second element customize the title content
Specify the visibility and the content of the title.
> The name comes from the `alt` attribute of an image element or the image name parsed from URL.
For example, `title: 4` equals to:
```js
new Viewer(image, {
title: [4, (image, imageData) => `${image.alt} (${imageData.naturalWidth} × ${imageData.naturalHeight})`]
});
```
### toolbar
- Type: `Boolean` or `Number` or `Object`
- Default: `true`
- Options:
- `0` or `false`: hide the toolbar.
- `1` or `true`: show the toolbar.
- `2`: show the toolbar only when the screen width is greater than 768 pixels.
- `3`: show the toolbar only when the screen width is greater than 992 pixels.
- `4`: show the toolbar only when the screen width is greater than 1200 pixels.
- `{ key: Boolean | Number }`: show or hide the toolbar.
- `{ key: String }`: customize the size of the button.
- `{ key: Function }`: customize the click handler of the button.
- `{ key: { show: Boolean | Number, size: String, click: Function }`: customize each property of the button.
- Available keys: "zoomIn", "zoomOut", "oneToOne", "reset", "prev", "play", "next", "rotateLeft", "rotateRight", "flipHorizontal" and "flipVertical".
- Available sizes: "small", "medium" (default) and "large".
Specify the visibility and layout of the toolbar its buttons.
For example, `toolbar: 4` equals to:
```js
new Viewer(image, {
toolbar: {
zoomIn: 4,
zoomOut: 4,
oneToOne: 4,
reset: 4,
prev: 4,
play: {
show: 4,
size: 'large',
},
next: 4,
rotateLeft: 4,
rotateRight: 4,
flipHorizontal: 4,
flipVertical: 4,
},
});
```
### className
- Type: `String`
- Default: `''`
Custom class name(s) to add to the viewer's root element.
### container
- Type: `Element` or `String`
- Default: `'body'`
- An element or a valid selector for [Document.querySelector](https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector)
The container to put the viewer in modal mode.
> Only available when the `inline` option is set to `false`.
### filter
- Type: `Function`
- Default: `null`
Filter the images for viewing (should return `true` if the image is viewable).
For example:
```js
new Viewer(image, {
filter(image) {
return image.complete;
},
});
```
### fullscreen
- Type: `Boolean`
- Default: `true`
Enable to request full screen when play.
> Requires the browser supports [Full Screen API](http://caniuse.com/fullscreen).
### initialViewIndex
- Type: `Number`
- Default: `0`
Define the initial index of image for viewing.
> Also used as the default parameter value of the `view` method.
### inline
- Type: `Boolean`
- Default: `false`
Enable inline mode.
### interval
- Type: `Number`
- Default: `5000`
The amount of time to delay between automatically cycling an image when playing.
### keyboard
- Type: `Boolean`
- Default: `true`
Enable keyboard support.
### loading
- Type: `Boolean`
- Default: `true`
Indicate if show a loading spinner when load image or not.
### loop
- Type: `Boolean`
- Default: `true`
Indicate if enable loop viewing or not.
> If the current image is the last one, then the next one to view is the first one, and vice versa.
### minWidth
- Type: `Number`
- Default: 200
Define the minimum width of the viewer.
> Only available in inline mode (set the `inline` option to `true`).
###
没有合适的资源?快使用搜索试试~ 我知道了~
基于js的viewer.js 强大的图片查看
共143个文件
js:92个
jpg:18个
md:6个
需积分: 50 23 下载量 70 浏览量
2018-11-21
15:13:14
上传
评论
收藏 2.95MB RAR 举报
温馨提示
基于js的viewer.js 强大的图片查看,各种姿势,基于js的viewer.js 强大的图片查看
资源推荐
资源详情
资源评论
收起资源包目录
基于js的viewer.js 强大的图片查看 (143个子文件)
.babelrc 185B
.browserslistrc 24B
.commitlintrc 53B
viewer.css 9KB
viewer.css 9KB
viewer.min.css 8KB
viewer.css 6KB
main.css 2KB
index.css 28B
.editorconfig 147B
.eslintrc 239B
.eslintrc 170B
.gitattributes 66B
.gitignore 31B
index.html 16KB
viewer-in-modal.html 4KB
custom-toolbar.html 3KB
dynamic-viewer.html 1KB
tibet-4.jpg 527KB
tibet-5.jpg 374KB
tibet-7.jpg 298KB
tibet-2.jpg 235KB
tibet-9.jpg 220KB
tibet-8.jpg 209KB
tibet-3.jpg 207KB
tibet-6.jpg 160KB
tibet-1.jpg 113KB
tibet-4.jpg 75KB
tibet-7.jpg 67KB
tibet-5.jpg 65KB
tibet-3.jpg 45KB
tibet-6.jpg 44KB
tibet-8.jpg 43KB
tibet-2.jpg 40KB
tibet-1.jpg 31KB
tibet-9.jpg 27KB
viewer.js 82KB
viewer.js 82KB
viewer.common.js 77KB
viewer.esm.js 77KB
viewer.min.js 30KB
methods.js 22KB
utilities.js 16KB
viewer.js 9KB
handlers.js 9KB
render.js 6KB
keyboard.spec.js 6KB
others.js 4KB
defaults.js 3KB
destroy.spec.js 3KB
main.js 3KB
constants.js 2KB
button.spec.js 2KB
events.js 2KB
zoom.spec.js 2KB
zoom.spec.js 2KB
prev.spec.js 2KB
next.spec.js 2KB
view.spec.js 2KB
helpers.js 2KB
inline.spec.js 2KB
backdrop.spec.js 2KB
view.spec.js 2KB
title.spec.js 1KB
zoomed.spec.js 1KB
hide.spec.js 1KB
zoomed.spec.js 1KB
exit.spec.js 1KB
full.spec.js 1KB
viewed.spec.js 1KB
hide.spec.js 1KB
container.spec.js 1KB
viewed.spec.js 1KB
show.spec.js 1KB
scale.spec.js 1KB
interval.spec.js 1KB
stop.spec.js 1KB
karma.conf.js 1KB
transition.spec.js 1KB
view.spec.js 1KB
zIndexInline.spec.js 1KB
play.spec.js 1KB
hide.spec.js 1KB
loop.spec.js 1KB
move.spec.js 1022B
className.spec.js 995B
rotateTo.spec.js 980B
zIndex.spec.js 972B
moveTo.spec.js 971B
rotate.spec.js 971B
toggleOnDblclick.spec.js 969B
filter.spec.js 964B
toggle.spec.js 964B
show.spec.js 947B
initialViewIndex.spec.js 942B
tooltip.spec.js 911B
loading.spec.js 907B
scalable.spec.js 906B
zoom.spec.js 905B
scaleY.spec.js 895B
共 143 条
- 1
- 2
资源评论
Caroline_Yang
- 粉丝: 6
- 资源: 17
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功