//判断滑动的方向
const glideDirection = ({fu, fd, fl, fr}) => {
let startX = null;
let startY = null;
let time;
return function(e) {
//获取滑动屏幕时的X,Y
const touch = e.changedTouches[0];
if(!startX) {
startX = touch.pageX;
startY = touch.pageY;
}
if(time) clearTimeout(time);
time = setTimeout(() => {
//获取滑动距离
let distanceX = touch.pageX - startX;
let distanceY = touch.pageY - startY;
//判断滑动方向
if(fr && Math.abs(distanceX)>Math.abs(distanceY) && distanceX>0){
// console.log('往右滑动');
fr()
}else if( fl && Math.abs(distanceX)>Math.abs(distanceY) && distanceX<0){
// console.log('往左滑动');
fl()
}else if(fu && Math.abs(distanceX)<Math.abs(distanceY) && distanceY<0){
// console.log('往上滑动');
fu()
}else if(fd && Math.abs(distanceX)<Math.abs(distanceY) && distanc
onTouchMove事件实现H5上下左右滚动
最新推荐文章于 2024-08-02 17:47:51 发布