前言
layer图片预览,并实现缩放
实现
代码复制直接可用
效果图
html中
只要放在layer-photos-demo中的图片都可用预览
复制代码
1
2
3
4
5
6
7
8
9<div id="layer-photos-demo"> <div> <img alt="" style="width:100px;" src="image/error.png"> </div> <div> <img alt="" style="width:100px;" src="image/error.png"> </div> </div>
js中
layer使用
复制代码
1
2
3
4
5
6
7
8// 查看图片 ====================================================================== layer.photos({ photos: '#layer-photos-demo' // 图片预览容器 ,zIndex: 99999999 // 弹出层级 ,shade: 0.2// 背景虚化 ,shift: 0 //0-6的选择,指定弹出图片动画类型,默认随机 });
实现滚动需要加入如下
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32/** * ------------------------------------------------------------------------------------------------------ * 图片预览-鼠标滚动缩放 * @param e * @returns */ $(document).on("mousewheel DOMMouseScroll", ".layui-layer-phimg img", function (e) { var delta = (e.originalEvent.wheelDelta && (e.originalEvent.wheelDelta > 0 ? 1 : -1)) || // chrome & ie (e.originalEvent.detail && (e.originalEvent.detail > 0 ? -1 : 1)); // firefox var imagep = $(".layui-layer-phimg").parent().parent(); var image = $(".layui-layer-phimg").parent();// layui-layer-phimg 是 layer.photos 弹出图片后的样式 var h = image.height(); var w = image.width(); if (delta > 0) { if (h < (window.innerHeight)) { h = h * 1.05; w = w * 1.05; } } else if (delta < 0) { if (h > 100) { h = h * 0.95; w = w * 0.95; } } imagep.css("top", (window.innerHeight - h) / 2); imagep.css("left", (window.innerWidth - w) / 2); image.height(h); image.width(w); imagep.height(h); imagep.width(w); });
最后
以上就是危机诺言最近收集整理的关于Layui图片预览,layer图片预览图片缩放,layui预览图片可放大放小的全部内容,更多相关Layui图片预览内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复