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

pull/1446/head
sight 2023-12-10 19:39:56 +08:00
parent 462ed13f18
commit 16121389da
1 changed files with 21 additions and 1 deletions

View File

@ -1601,6 +1601,26 @@ layer.photos = function(options, loop, key){
e.preventDefault(); 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 ? ( window.layui && layui.define ? (
layer.ready(), layer.ready(),
layui.define('jquery', function(exports){ // layui layui.define(['jquery','lay'], function(exports){ // layui
layer.path = layui.cache.dir; layer.path = layui.cache.dir;
ready.run(layui.$); ready.run(layui.$);