From 16121389dadd6ad28fafb075e812842664210668 Mon Sep 17 00:00:00 2001 From: sight <1453017105@qq.com> Date: Sun, 10 Dec 2023 19:39:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20layer.photo=20=E7=A7=BB?= =?UTF-8?q?=E5=8A=A8=E7=AB=AF=E6=BB=91=E5=8A=A8=E5=88=87=E6=8D=A2=E5=9B=BE?= =?UTF-8?q?=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/layer.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/modules/layer.js b/src/modules/layer.js index f5007fc2..74edbe96 100644 --- a/src/modules/layer.js +++ b/src/modules/layer.js @@ -1601,6 +1601,26 @@ layer.photos = function(options, loop, key){ e.preventDefault(); }); + // 滑动切换图片事件,仅限 layui 中 + if(window.layui || window.lay){ + var lay = window.layui.lay || window.lay; + var touchEndCallback = function(e, state){ + var threshold = 40; + var shouldSwipe = Math.abs(state.deltaX) > threshold; + if(!shouldSwipe) return; + if(state.direction === 'left'){ + dict.imgnext(true); + }else if(state.direction === 'right'){ + dict.imgprev(true); + } + } + + $.each([that.shadeo, dict.main], function(i, elem){ + lay.touchSwipe(elem, { + onTouchEnd: touchEndCallback + }) + }) + } }; // 图片预加载 @@ -1761,7 +1781,7 @@ ready.run = function(_$){ // 加载方式 window.layui && layui.define ? ( layer.ready(), - layui.define('jquery', function(exports){ // layui + layui.define(['jquery','lay'], function(exports){ // layui layer.path = layui.cache.dir; ready.run(layui.$);