layer.photos的替代品viewer.js

layui自带模块图片展示,名叫相册层

https://layui.gitee.io/v2/docs/modules/layer.html#layer.photos

但是没有缩放(放大,缩小)和旋转

layer.photos({
  //photos: '#imgListbox' //方法1,图片父容器选择器
  photos: { "data": [{"src": '1.jpg'},{"src": '2.jpg'}] } //方法2,json
  ,anim: 5 //0-6的选择,指定弹出图片动画类型,默认随机
});

所以使用viewer.js代替

如果你用原生js,只要

https://github.com/fengyuanchen/viewerjs

两个文件viewer.js和viewer.css

演示

https://fengyuanchen.github.io/viewerjs/

如果你用jquery,上面的基础上,另外:

jquery.js依赖

https://github.com/fengyuanchen/jquery-viewer

jquery-viewer.js

演示

https://fengyuanchen.github.io/jquery-viewer/

使用方法:

<div>
  <img id="image_one" src="picture.jpg" alt="Picture">
</div>

<div>
  <ul id="imagesbox">
    <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原生

let viewer = new Viewer(document.getElementById('image_one'), {
  inline: true
  ,viewed() {
    viewer.zoomTo(1);
  }
});
//element.querySelectorAll('img')
let one = new Viewer(document.getElementById('imagesbox'));

jquery

$('#image_one').viewer({
  inline: true,
  viewed: function() {
    $('#image_one').viewer('zoomTo', 1);
  }
});

// Get the Viewer.js instance after initialized
// var viewer = $image.data('viewer');

$('#imagesbox').viewer();

重要的参数是url

<img id="image" data-original="big.jpg" src="small.jpg" alt="图片1">
//js版
var image = new Viewer(document.getElementById('image'),{
  url: 'data-original' //默认为src,这里为原生大图
});
或jquery
$('#image').viewer({
  url: 'data-original' //默认为src,这里为原生大图
});

其它一些附加参数,选用

url 字符串/函数 src 设置大图片的 url

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

build 函数 null 回调函数,具体查看演示
built 函数 null 回调函数,具体查看演示
show 函数 null 回调函数,具体查看演示
shown 函数 null 回调函数,具体查看演示
hide 函数 null 回调函数,具体查看演示
hidden 函数 null 回调函数,具体查看演示
view 函数 null 回调函数,具体查看演示
viewed 函数 null 回调函数,具体查看演示

--over--

点赞

发表评论

电子邮件地址不会被公开。必填项已用 * 标注