Viewer.js的使用

viewer.js GitHub地址:https://github.com/fengyuanchen/viewerjs

https://github.com/fengyuanchen/viewer

两个版本的使用方式不完全相同;

尽管作者已经将使用方法都列出了(https://github.com/fengyuanchen/viewerjs#table-of-contents),但还是记录一下。

1.2.0可以控制每一个按钮的显示、显示场景以及点击事件

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.


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,
}

viewer.js将标签下的所有元素扩展了viewer()方法,可以通过传入配置参数的方式来进行配置;支持的配置项:

名称类型默认值说明
inline布尔值false启用 inline 模式
button布尔值true显示右上角关闭按钮(jQuery 版本无效)
navbar布尔值/整型true显示缩略图导航
title布尔值/整型true显示当前图片的标题(现实 alt 属性及图片尺寸)
toolbar布尔值/整型true显示工具栏
tooltip布尔值true显示缩放百分比
movable布尔值true图片是否可移动
zoomable布尔值true图片是否可缩放
rotatable布尔值true图片是否可旋转
scalable布尔值true图片是否可翻转
transition布尔值true使用 CSS3 过度
fullscreen布尔值true播放时是否全屏
keyboard布尔值true是否支持键盘
interval整型5000播放间隔,单位为毫秒
zoomRatio浮点型0.1鼠标滚动时的缩放比例
minZoomRatio浮点型0.01最小缩放比例
maxZoomRatio数字100最大缩放比例
zIndex数字2015设置图片查看器 modal 模式时的 z-index
zIndexInline数字0设置图片查看器 inline 模式时的 z-index
url字符串/函数src设置大图片的 url
build函数null回调函数,具体查看演示
built函数null回调函数,具体查看演示
show函数null回调函数,具体查看演示
shown函数null回调函数,具体查看演示
hide函数null回调函数,具体查看演示
hidden函数null回调函数,具体查看演示
view函数null回调函数,具体查看演示
viewed函数null回调函数,具体查看演示

1.0.0版本:表格中列举的并不全面,具体可以到GitHub上查看源码, 比如container也是可以作为配置参数传入的,这个参数将会把viewer展示到匹配的元素中:

我们通过上面代码可以看出,在iframe中调用全屏展示时只会在这个窗口展示;


另外还有一些函数可以调用,具体有哪些方法可以看源码中的methods方法;

调用方法例如:

1.0.0:   

$(pictureDiv).viewer('destroy');

1.2.0:    

viewer = new Viewer(pictureDiv,{
       inline: true,
       url: 'data-original',
       navbar: false,
       zoomRatio: 0.4,
       button: true,
       title: false,
       keyboard: false,
       toolbar: {
           zoomIn: 1,
           zoomOut: 1,
           oneToOne: 1,
           reset: 1,
           prev: 0,
           play: 0,
           next: 0,
           rotateLeft: 1,
           rotateRight: 1,
           flipHorizontal: 1,
           flipVertical: 1,
       },
       viewed: function () {
           viewer.view(0);
       }
   });

 

 

 

  • 7
    点赞
  • 49
    收藏
    觉得还不错? 一键收藏
  • 24
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 24
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值