定时器仍会保留一个数字值,需要手动清零。
React分别设置绑定onTouchStart() onTouchMove() onTouchEnd()实现长按识别
onTouchStart(){
this.timeOutEvent = setTimeout(function() {
this.timeOutEvent = 0;
console.log(‘你长按了’);
}, 400);
}
onTouchMove() {
clearTimeout(this.timeOutEvent);
this.timeOutEvent = 0;
}
onTouchEnd() {
clearTimeout(this.timeOutEvent);
if (this.timeOutEvent != 0) {
console.log('你点击了');
}
return false;
}