• Stars
    star
    176
  • Rank 209,322 (Top 5 %)
  • Language
    JavaScript
  • Created over 7 years ago
  • Updated about 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

H5图片查看器—Imageview component built with react

中文 | English

React图片查看器

使用React打造的H5图片查看器

特性

  • 各类手势快速响应
  • 急速滑动翻页
  • 支持双指缩放、旋转、双击放大
  • 支持放大后局部拖拽、翻页
  • 支持超长(纵向)拼接图查看
  • 支持下载
  • 图片懒加载、预加载

示例

您可以下载代码在examples文件夹中找到例子或者在线示例

使用方法

1、安装NPM依赖

npm install react-imageview --save

2、随意使用

// 例 1:

import React, { Component } from 'react'
import ImageView from 'react-imageview'

import 'react-imageview/dist/react-imageview.min.css'

class Main extends Component {
    state = {
        showViewer: false
    }
    render() {
        const imagelist = ['./1.png','./2.png','./3.png','./4.png']
        return (
            <div>
                {
                    !!this.state.showViewer && <ImageView imagelist={imagelist} close={this.close.bind(this)} />
                }
                <button onClick={e=>this.show()}>click me to show Alert</button>
            </div>
        )
    }
    show() {
        this.setState({ showViewer: true })
    }
    close() {
        this.setState({ showViewer: false})
    }
}

// 例 2(推荐使用):

import { SingleImgView } from 'react-imageview'
import 'react-imageview/dist/react-imageview.min.css'

const imagelist = ['./1.png','./2.png','./3.png','./4.png']

// 仅创建一个ImageView实例
SingleImgView.show({ 
    imagelist, 
    close: () => { SingleImgView.hide() } 
});

配置说明

参数 类型 描述 必需 默认值
imagelist array 要预览的图片列表
current number 当前展示的图片序号(从0开始) 0
close function 图片查看器关闭方法
gap number 轮播图间距 30
maxScale number 最大缩放倍数 2
disablePinch bool 禁用缩小放大 false
enableRotate bool 启用旋转 否(默认关闭) false
disableDoubleTap bool 禁用双击放大 false
initCallback function 初始化后回调
longTap function 长按回调
changeIndex function 轮播后回调

English | 中文

react-imageview

Imageview component built with react

Demo

You can download the code and find demo in folder which is named as examples or demo online

Usage with React

1、Install the package

npm install react-imageview --save

2、Using as your need

// Example 1:

import React, { Component } from 'react'
import ImageView from 'react-imageview'

import 'react-imageview/dist/react-imageview.min.css'

class Main extends Component {
    state = {
        showViewer: false
    }
    render() {
        const imagelist = ['./1.png','./2.png','./3.png','./4.png']
        return (
            <div>
                {
                    !!this.state.showViewer && <ImageView imagelist={imagelist} close={this.close.bind(this)} />
                }
                <button onClick={e=>this.show()}>click me to show Alert</button>
            </div>
        )
    }
    show() {
        this.setState({ showViewer: true })
    }
    close() {
        this.setState({ showViewer: false})
    }
}

// Example 2(Recommended):

import { SingleImgView } from 'react-imageview'
import 'react-imageview/dist/react-imageview.min.css'

// You can call SingleImgView.show anywhere and anytime, there will be only one View DOM node be added.

const imagelist = ['./1.png','./2.png','./3.png','./4.png']
SingleImgView.show({
    imagelist, 
    close: () => { SingleImgView.hide() } 
});

Configuration

Param Type Description Required
imagelist array The list of images to view Yes
current number The current image to first view No
close function The method to close the viewer Yes
disablePinch bool Disable pinch function No
disableRotate bool Disable rotate function No
disableDoubleTap bool Disable double tap function No
longTap function Events called after the long tap No

License

Copyright(c) 2016-2017 AlloyTeam. Licensed under MIT license.

More Repositories

1

Mars

腾讯移动 Web 前端知识库
9,586
star
2

AlloyFinger

Super tiny size multi-touch gestures library for the web.    You can touch this →
JavaScript
3,403
star
3

AlloyImage

基于HTML5的专业级图像处理开源引擎。An image processing lib based on html5.
JavaScript
3,002
star
4

PhyTouch

Smooth scrolling, rotation, pull to refresh, page transition and any motion for the web - 丝般顺滑的触摸运动方案
JavaScript
2,954
star
5

eslint-config-alloy

Progressive ESLint config for your React/Vue/TypeScript projects
JavaScript
2,614
star
6

AlloyLever

1kb js library contains development debugging, error monitoring and reporting, user problem localization features - 1KB代码搞定开发调试发布,错误监控上报,用户问题定位
JavaScript
1,381
star
7

curvejs

Made curve a dancer in HTML5 canvas - 魔幻线条
JavaScript
1,300
star
8

CodeGuide

Alloyteam代码规范
HTML
1,275
star
9

JX

JX(Javascript eXtension tools) 是腾讯AlloyTeam推出的模块化、非侵入式Web前端框架,适合构建和组织工业级大规模、高效率的 Web App
JavaScript
1,156
star
10

AlloyCrop

The best and tiny size mobile cropping component - 做最好且最小的移动裁剪组件
JavaScript
940
star
11

Rythem

a fiddler-like project using Qt
C++
878
star
12

alloyteam.github.com

腾讯 AlloyTeam 开源项目官网 - 我们的愿景: 成为业界卓越的Web团队!
JavaScript
846
star
13

alloy-worker

面向事务的高可用 Web Worker 通信框架
TypeScript
635
star
14

AlloyStick

AlloyStick 骨骼动画引擎 - 腾讯 AlloyTeam
JavaScript
430
star
15

Rosin

A tool for web developers debug mobile page with fiddler. http://alloyteam.github.io/Rosin/
C#
310
star
16

StreetFighter

街霸StreetFighter
JavaScript
301
star
17

webtop

HTML5 本地App开发引擎
C++
290
star
18

AlloyPhoto

JavaScript
276
star
19

gopng

GoPng - a HTML5 css sprite generator with cool feature.
272
star
20

sodajs

Light weight but powerful template engine for JavaScript
JavaScript
256
star
21

tslint-config-alloy

AlloyTeam TSLint 规则
JavaScript
205
star
22

JXAnimate

基于CSS3的并行动画、声音引擎 - JX.Animate
CSS
192
star
23

AlloyTimer

AlloyTimer定时器 - 番茄工作法的时间管理应用
JavaScript
190
star
24

JMUI

移动Web开发UI组件库
JavaScript
178
star
25

JM

面向Mobile的极致JavaScript库
JavaScript
141
star
26

AlloyDesigner

AlloyDesigner是一款致力于提高前端生产效率的浏览器内运行工具,AlloyDesigner + Chrome F12(Especially with WorkSpace) 打造前端新的开发和测试模式
138
star
27

omi-cli

Create website with no build configuration - 创建网站无需任何配置
JavaScript
126
star
28

AlloyPullRefresh

JavaScript
119
star
29

Spirit

腾讯移动Web整体解决方案
CSS
117
star
30

CodeTank

CodeTank(代码坦克)是全世界首款 Javascript 程序员的游戏, 由腾讯 AlloyTeam 用 HTML5、Javascript 等 Web 新技术来构建一个基于互联网的智能坦克机器人战斗仿真引擎
112
star
31

AlloyClip

A PC & Mobile Image Clip Kit based on AlloyImage
JavaScript
108
star
32

MLogger

一个浮在页面上的日志查看工具
JavaScript
100
star
33

Abstract.js

Abstract.js is a web framework for fast development
JavaScript
46
star
34

AlloyLint

apply eslint autofix but keep last author info in git blame。运行 eslint 的自动修复,但是保留最后修改人的信息
TypeScript
41
star
35

AlloyFlow

made workflow simple
JavaScript
39
star
36

AlloyTicker

The Master of Time          DEMO
JavaScript
25
star
37

netural

JavaScript前向神经网络(推理)和反向传播(训练)的实现
JavaScript
21
star