如何在 hammer.js 中接收 two/one 手指和 single/double 敲击的组合

How can I receive combinations of two/one finger and single/double taps in hammer.js

我正在尝试使用 hammer.js

接收三种类型的点击事件
  1. 用一根手指单击
  2. 用一根手指双击
  3. 用两个手指双击

如何在 hammer.js

中正确设置它

这是我目前拥有的:

  if (mc == null) {
    mc = new Hammer.Manager(el);
  }
  mc.set({ touchAction: "none" });
  //mc.get("swipe").set({direction: Hammer.DIRECTION_ALL, pointers: 2});'
  //mc.get('tap').set({enable: false});
  var singletap = new Hammer.Tap({
    event: "singletap",
    taps: 1,
    pointers: 1
  });

  var doubletap = new Hammer.Tap({
    event: "doubletap",
    taps: 2,
    pointers: 1
  });
  var twodoubletap = new Hammer.Tap({
    event: "twodoubletap",
    taps: 2,
    pointers: 2
  });

  mc.add([twodoubletap, doubletap,singletap]);//, twotap, threetap]);

  twodoubletap.recognizeWith([doubletap,singletap])
  doubletap.recognizeWith([singletap,twodoubletap])

  //doubletap.requireFailure(twodoubletap);

  singletap.requireFailure([doubletap,twodoubletap]);

  mc.on("twodoubletap doubletap singletap", binding.value);

我可以通过单击来持续开火,有时用一根手指双击。

双指双击要么不触发,要么与紧随其后的另一个点击一起触发。

理想情况下,我希望每种类型的水龙头都能持续触发。

我通过做三件事来让它工作。 1. 我将 dropRequireFailure 添加到其他水龙头的 two-fingerdouble 水龙头 2.我在事件中把门槛提高了。 3. 我在事件处理程序中添加了一个 time-based 过滤器,用于拒绝彼此距离太近的点击。我知道这并不理想,但它现在有效。

          if (mc == null) {
            mc = new Hammer.Manager(el);
          }
          mc.set({ touchAction: "none" });
          //mc.get("swipe").set({direction: Hammer.DIRECTION_ALL, pointers: 2});'
          //mc.get('tap').set({enable: false});
          var singletap = new Hammer.Tap({
            event: "singletap",
            taps: 1,
            pointers: 1,
            interval: 500,
            threshold: 200,
            posThreshold: 200
          });

          var doubletap = new Hammer.Tap({
            event: "doubletap",
            taps: 2,
            pointers: 1,
            interval: 300,
            threshold: 200,
            posThreshold: 200
          });
          var twodoubletap = new Hammer.Tap({
            event: "twodoubletap",
            taps: 2,
            pointers: 2,
            interval: 400,
            threshold: 500,
            posThreshold: 200
          });

          mc.add([twodoubletap, doubletap,singletap]);//, twotap, threetap]);

          twodoubletap.recognizeWith([doubletap,singletap])
          doubletap.recognizeWith([twodoubletap])

          doubletap.requireFailure(twodoubletap);
          singletap.requireFailure([doubletap,twodoubletap]);
          twodoubletap.dropRequireFailure(doubletap);
          twodoubletap.dropRequireFailure(singletap);

          mc.on("twodoubletap doubletap singletap", handler);

然后在事件处理程序的顶部:

      let now = Date.now();
      if((now - lastTap)<500){
        return;
      }
      lastTap = now;