我正在寻找一个在移动应用程序的HTML元素上开始和结束触摸的Ionic 3单独事件处理程序。
我发现许多相关的和已解决的问题,但没有针对Ionic 3的解决方案,目前它似乎只支持“tap、press、pan、swipe、rotate和pinch”(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
}
}
HTML:
<button ion-button type="button" (button_touch_started) = "touched($event)" (button_touch_ended) = "touch_ended($event)">Touch button</button>
高精度(低至毫秒级别)对于触摸起始时间尤为重要。
欢迎提供任何建议。
<button ion-button type="button" (button_touch_started)="touched()">Touch this button</button>
(或者如果是<div>
是否有区别?) - gaspar