html - ionic 3 中的 touchstart 和 touchend 事件

标签 html ionic3 touch dom-events touchstart

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

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

对于更多上下文,我想要的是在屏幕第一次触摸元素的确切时刻清除相关超时,然后查看对同一特定元素的触摸是否在特定时间内结束(例如250 ms,因此可以将其评估为“点击”)。

例如这样的:

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>

高精度(低至毫秒)非常重要,尤其是对于触摸开始时间。

感谢任何建议。

最佳答案

HTML 尝试 div 或按钮

<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>

Ts

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

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

关于html - ionic 3 中的 touchstart 和 touchend 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49650373/

相关文章:

php - 导航栏上的下拉菜单。 -下拉按钮与其余导航按钮不对齐。 HTML

angular - Ion-slides 不更新动态数据

html - 将输入字段左对齐

css - iOS 上的 Ionic 3 全屏视频背景

slider - Swiper 触摸事件 - 启用点击但禁用拖动

php - 快速可靠地更新聊天室的最佳方法?

html - 引导安装 MVC 4 后无法整理登录页面

javascript - GMap 绘图工具转图像 jpeg [静态 map URL]

ios - Swift - 如果在 View 外部触摸则隐藏 View

ios - 从图像获取触摸坐标,同时保持平移/缩放功能