小程序长按事件
小程序长按事件
·
注意:这些事件要有效果必须这样使用,如: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() //响应事件
}
},
- 使用 touchstart 来记录点击的开始时间,touchend 来记录点击的结束时间,当两者时间相差大于等于2秒就响应事件;
- 响应事件后记得将 touchstart 和 touchend 的数据清空,因为时间戳是在原来的基础上累加的。
更多推荐
已为社区贡献3条内容
所有评论(0)