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.$);