Compare commits
4 Commits
336125dd89
...
177a4dfe32
Author | SHA1 | Date |
---|---|---|
|
177a4dfe32 | 1 week ago |
|
e28702074d | 1 week ago |
|
b5c3dc4766 | 1 week ago |
|
b19667794e | 1 week ago |
Before Width: | Height: | Size: 611 B After Width: | Height: | Size: 611 B |
Before Width: | Height: | Size: 586 B After Width: | Height: | Size: 586 B |
Before Width: | Height: | Size: 576 B After Width: | Height: | Size: 576 B |
Before Width: | Height: | Size: 87 KiB After Width: | Height: | Size: 87 KiB |
Before Width: | Height: | Size: 87 KiB |
Before Width: | Height: | Size: 22 KiB |
Before Width: | Height: | Size: 14 KiB |
@ -0,0 +1,47 @@
@@ -0,0 +1,47 @@
|
||||
// 长按弹出上拉操作面板
|
||||
class Mobile { |
||||
toucheX: number = 0; |
||||
toucheY: number = 0; |
||||
timeOutEvent: number = 0; |
||||
data?: any; |
||||
onLongTouch?: Function; |
||||
onClick?: Function; |
||||
e: any; |
||||
|
||||
onTouchStart(e, data) { |
||||
this.toucheX = e.targetTouches[0].screenX; |
||||
this.toucheY = e.targetTouches[0].screenY; |
||||
this.data = data; |
||||
this.e = e; |
||||
|
||||
// 开启定时器前先清除定时器,防止重复触发
|
||||
this.timeOutEvent && clearTimeout(this.timeOutEvent); |
||||
// 显示上拉面板
|
||||
this.timeOutEvent = setTimeout(() => { |
||||
this.onLongTouch && this.onLongTouch(e, data); |
||||
this.timeOutEvent = 0; |
||||
}, 1000); |
||||
e.preventDefault(); // 阻止系统默认事件
|
||||
} |
||||
onTouchMove(e) { |
||||
const moveX = e.targetTouches[0].screenX; |
||||
const moveY = e.targetTouches[0].screenY; |
||||
// 解决vivo机型,手指没有move,touchmove事件仍然会调用而导致setTimeout被clear
|
||||
if (this.toucheX !== moveX || this.toucheY !== moveY) { |
||||
// 手指滑动,清除定时器,中断长按逻辑
|
||||
this.timeOutEvent && clearTimeout(this.timeOutEvent); |
||||
} |
||||
} |
||||
onTouchEnd() { |
||||
// 清除定时器,结束长按逻辑
|
||||
this.timeOutEvent && clearTimeout(this.timeOutEvent); |
||||
// 若手指离开屏幕,时间小于我们设置的长按时间,则为点击事件
|
||||
if (this.timeOutEvent !== 0) { |
||||
this.onClick && this.onClick(this.e, this.data); |
||||
} |
||||
} |
||||
} |
||||
|
||||
export const userMobile = () => { |
||||
return new Mobile(); |
||||
}; |