Browse Source

优化 layer.photo 移动端滑动切换图片

pull/1446/head
sight 12 months ago
parent
commit
16121389da
  1. 22
      src/modules/layer.js

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

Loading…
Cancel
Save