我是靠谱客的博主 帅气电话,这篇文章主要介绍layer.photos 图片弹出无法滚轮放大缩写的问题解决,现在分享给大家,希望可以做个参考。

layui的版本问题,在旧版本中下列方式可以实现滚轮放大缩小,但是出现新的业务场景,需要增加评价项,如图。评价项需要引用rate.js,但是旧版本中没有,引用了新版本后,发现照片可以预览,但是滚轮放大缩小失效了
在这里插入图片描述

HTML

复制代码
1
2
3
4
5
6
7
8
<div class="layui-form-item"> <label class="layui-form-label">故障图片:</label> <div class="layui-input-inline" style="margin: 10px" v-for="imageUrl in imageList"> <img :src="imageUrl" style="width: 150px;height: 150px;" aria-readonly="true" @click="iamgeUrlAmplify"> </div> </div>

JS

复制代码
1
2
3
4
5
6
7
iamgeUrlAmplify: function (e) { var url = e.target.src; layer.photos({ photos: {"data": [{"src": e.target.src}]}, }); },

解决办法
在原JS中加入下面这段代码即可放大缩小

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
$(document).on("mousewheel",".layui-layer-photos",function(ev){ var oImg = this; var ev = event || window.event;//返回WheelEvent //ev.preventDefault(); var delta = ev.detail ? ev.detail > 0 : ev.wheelDelta < 0; var ratioL = (ev.clientX - oImg.offsetLeft) / oImg.offsetWidth, ratioT = (ev.clientY - oImg.offsetTop) / oImg.offsetHeight, ratioDelta = !delta ? 1 + 0.1 : 1 - 0.1, w = parseInt(oImg.offsetWidth * ratioDelta), h = parseInt(oImg.offsetHeight * ratioDelta), l = Math.round(ev.clientX - (w * ratioL)), t = Math.round(ev.clientY - (h * ratioT)); $(".layui-layer-photos").css({ width: w, height: h ,left: l, top: t }); $("#layui-layer-photos").css({width: w, height: h}); $("#layui-layer-photos>img").css({width: w, height: h}); });

完整JS

复制代码
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
iamgeUrlAmplify: function (e) { var url = e.target.src; layer.photos({ photos: {"data": [{"src": e.target.src}]}, success:function () { $(document).on("mousewheel",".layui-layer-photos",function(ev){ var oImg = this; var ev = event || window.event;//返回WheelEvent //ev.preventDefault(); var delta = ev.detail ? ev.detail > 0 : ev.wheelDelta < 0; var ratioL = (ev.clientX - oImg.offsetLeft) / oImg.offsetWidth, ratioT = (ev.clientY - oImg.offsetTop) / oImg.offsetHeight, ratioDelta = !delta ? 1 + 0.1 : 1 - 0.1, w = parseInt(oImg.offsetWidth * ratioDelta), h = parseInt(oImg.offsetHeight * ratioDelta), l = Math.round(ev.clientX - (w * ratioL)), t = Math.round(ev.clientY - (h * ratioT)); $(".layui-layer-photos").css({ width: w, height: h ,left: l, top: t }); $("#layui-layer-photos").css({width: w, height: h}); $("#layui-layer-photos>img").css({width: w, height: h}); }); },end: function(){ //销毁回调 } });

代码来源:前端学习之layui照片查看器缩放

最后

以上就是帅气电话最近收集整理的关于layer.photos 图片弹出无法滚轮放大缩写的问题解决的全部内容,更多相关layer.photos内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(78)

评论列表共有 0 条评论

立即
投稿
返回
顶部