Javascript - 禁用多点触控

时间:2016-06-13 09:07:51

标签: javascript multi-touch

我正试图在我的1920x1080触摸屏上阻止多点触控。

this.el.addEventListener('touchstart', function (e) {

  if (this.multiTouch.disable(e)) {

    this.triggerTouch(e);

  }

}.bind(this));

multiTouch.disable函数返回true或false。这是功能:

disable: function (e) {

  if (e.touches.length > 1 || e.targetTouches.length > 1) {

    e.preventDefault();
    e.stopPropagation();
    e.stopImmediatePropagation();

    return false;

  } else {

    return true;

  }

}

所以在这个函数中我会检查注册的触摸次数。如果有多个触摸注册它的多点触控,那么它应该被阻止。

但是当我将以下语句添加到this.el eventlistener console.log(this.multiTouch.disable(e))时,我得到这样的日志:

true TouchPoint.js:36
(11) false TouchPoint.js:36
true TouchPoint.js:36
10false TouchPoint.js:36
true TouchPoint.js:36
(7) false TouchPoint.js:36
true TouchPoint.js:36
(6) false TouchPoint.js:36
true TouchPoint.js:36
(8) false TouchPoint.js:36
true TouchPoint.js:36
(7) false TouchPoint.js:36
true TouchPoint.js:36
(6) false TouchPoint.js:36

这是用三个或更多手指触摸屏幕时。第一个触摸开始始终只记录一次触摸,因此禁用功能将始终在第一次返回true。

如何使用JavaScript正确阻止多点触控?

0 个答案:

没有答案