Skip to content

Commit 71449a9

Browse files
committed
Resolve touch through issue with a global timestamp
1 parent c0c3e4a commit 71449a9

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

index.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ var isPassiveSupported = (function() {
3131
return supportsPassive;
3232
})();
3333

34+
// Save last touch time globally (touch start time or touch end time), if a `click` event triggered,
35+
// and the time near by the last touch time, this `click` event will be ignored. This is used for
36+
// resolve touch through issue.
37+
var globalLastTouchTime = 0;
3438

3539
var vueTouchEvents = {
3640
install: function (Vue, constructorOptions) {
@@ -51,10 +55,10 @@ var vueTouchEvents = {
5155
$el = this;
5256

5357
if (isTouchEvent) {
54-
$this.lastTouchStartTime = event.timeStamp;
58+
globalLastTouchTime = event.timeStamp;
5559
}
5660

57-
if (isMouseEvent && $this.lastTouchStartTime && event.timeStamp - $this.lastTouchStartTime < 350) {
61+
if (isMouseEvent && globalLastTouchTime && event.timeStamp - globalLastTouchTime < 350) {
5862
return;
5963
}
6064

@@ -131,7 +135,7 @@ var vueTouchEvents = {
131135
isMouseEvent = event.type.indexOf('mouse') >= 0;
132136

133137
if (isTouchEvent) {
134-
$this.lastTouchEndTime = event.timeStamp;
138+
globalLastTouchTime = event.timeStamp;
135139
}
136140

137141
var touchholdEnd = isTouchEvent && !$this.touchHoldTimer;
@@ -141,7 +145,7 @@ var vueTouchEvents = {
141145

142146
removeTouchClass(this);
143147

144-
if (isMouseEvent && $this.lastTouchEndTime && event.timeStamp - $this.lastTouchEndTime < 350) {
148+
if (isMouseEvent && globalLastTouchTime && event.timeStamp - globalLastTouchTime < 350) {
145149
return;
146150
}
147151

@@ -298,6 +302,7 @@ var vueTouchEvents = {
298302
// change the passive option for the moving event if disablePassive modifier exists
299303
passiveOpt = false;
300304
}
305+
// fallthrough
301306
default:
302307
$this.callbacks[eventType] = $this.callbacks[eventType] || [];
303308
$this.callbacks[eventType].push(binding);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue2-touch-events",
3-
"version": "3.0.1",
3+
"version": "3.1.0",
44
"description": "Simple touch events support for vueJS2",
55
"main": "index.js",
66
"types": "index.d.ts",

0 commit comments

Comments
 (0)