2019年4月12日 layer版本 layer-v3.1.1
layer.photos 方法在使用過程中發現沒有通過鼠標中鍵(滾軸)實現圖片縮放功,故通過搜索引擎找到如下方法
需要引用 jquery
$(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();
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);
});
此方法可以實現鼠標中鍵(滾軸)縮放,但是在實際項目中還是相冊功能不符合:切換圖片的箭頭,在圖片內顯示,也即是說箭頭總是跟隨圖片的變化而變化。