注意:这些事件要有效果必须这样使用,如:bind:touchstart 或者  capture-bind:touchstart

如果要实现长按1s以上的事件,使用 longpress 和  logtap 是没用的,毕竟它们都是在350ms后就响应了。因此需要 touchstart 和 touchend 一起使用。

  touchstart(e){
    this.setData({
      touchstart:e.timeStamp
    })
  },

 touchend(e){
    this.setData({
      touchend:e.timeStamp
    })
    if((this.data.touchend-this.data.touchstart)>=2000){  /*长按两秒*/
        this.longpress() //响应事件
    }
  },
  1. 使用 touchstart 来记录点击的开始时间,touchend  来记录点击的结束时间,当两者时间相差大于等于2秒就响应事件;
  2. 响应事件后记得将 touchstart  和 touchend  的数据清空,因为时间戳是在原来的基础上累加的。

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐