ionic 3中的touchstart和touchend事件

gas*_*par 0 html javascript-events touch touchstart ionic3

我正在Ionic 3中寻找单独的事件处理程序,以开始和结束对移动应用程序上HTML元素的触摸。

我发现了许多相关且已解决的问题,但对于Ionic 3却没有,目前似乎仅支持“点击,按下,平移,滑动,旋转和捏合”(https://ionicframework.com/docs/components/#gestures) 。这些似乎都没有在开始时提供“处理程序”,而只是在结束时提供了“处理程序”。我看到,然后它们确实提供了触摸持续时间(deltaTime)的数据,但是到那时为止,这对我而言毫无用处。

要获得更多背景信息,我想清除的是在第一次触摸某个元素的确切时间里的相关超时,然后查看同一特定元素上的触摸是否在一定时间内(例如250毫秒,以便可以将其评估为“点击”)。

例如这样的事情:

JS:

timeout_1 = setTimeout(function() {
    // do something if timeout_1 not cleared by touch start
}, 4000);

touched(event) {
    clearTimeout(timeout_1);
    touching_x = true
    timeout_2 = setTimeout(function() {
        touching_x = false
        // store event details and do other things if timeout_2 not cleared by touch end
    }, 250);
}

touch_ended(event) { 
    if (touching_x==true) {
        clearTimeout(timeout_2);    
        // store event details and do some other things
    }
}
Run Code Online (Sandbox Code Playgroud)

HTML:

<button ion-button type="button" (button_touch_started) = "touched($event)" (button_touch_ended) = "touch_ended($event)">Touch button</button>
Run Code Online (Sandbox Code Playgroud)

高精度(低至ms)对于触摸开始时间尤其重要。

任何建议表示赞赏。

Abi*_*yel 5

HTML 尝试div或button

<div style="height:100%;width:100%" (touchstart)="touchstart($event)" (touchend)="touchend($event)">
  </div>
  <button ion-button large primary (touchstart)="touchstart($event);">touchstart</button>
<button ion-button large primary (touchend)="touchend($event);">touchend</button>
Run Code Online (Sandbox Code Playgroud)

s

touchstart(event){
    console.log(event);
  }

  touchend(event){
    console.log(event);
  }
Run Code Online (Sandbox Code Playgroud)