HammerJs:未检测到单键和双击

时间:2018-11-08 17:45:56

标签: javascript tap

将自己的识别器设置为

buildHammer(element: HTMLElement): HammerInstance {
  let mc = new Hammer(element, { domEvents: true });
  let doubleTap = new Hammer.Tap({
    event: "doubletap",
    taps: 2
  });
  let singleTap = new Hammer.Tap({ event: "singletap" });
  mc.add([singleTap, doubleTap]);
  doubleTap.recognizeWith(singleTap);
  singleTap.requireFailure(doubleTap);

  mc.on("doubleTap", function(e) {
    console.log("double tap");
  });

  mc.on("singleTap", function(e) {
    console.log("single tap");
  });

  return mc;

}

将事件附加到HTML元素时不会触发

<div (doubleTap)="onDoubleTap($event)" (singleTap)="onSingleTap($event)">

但是,如果我将Hammerjs识别器“ tap”用作

,效果很好
<div (tap)="onTap($event)">

并使用event.tapCount

上一个是否有我做错的事情?

0 个答案:

没有答案