1、问题描述:
在**touchstart**事件中用setInterval()判断按住超过1S的为长按事件,低于1S的**还原默认事件**(需要浏览器滚动事件)。
但是下面的代码没有效果,请教下问题所在:
2、代码:
function isScroll(event){
event.preventDefault();
}
function touchStart(event){
elem = event.target;
**document.addEventListener('touchstart',isScroll);**
var touch = event.touches[0];
startX = parseInt(touch.pageX);
startY = parseInt(touch.pageY);
var j =0;
timer = setInterval(function(){
j += 10;
//长按1s后
if(j >= 1000){
document.addEventListener('touchstart',isScroll);
if($(elem).hasClass('list')){
$(elem).css({
'box-shadow' : '0 0 18px rgba(111,111,200,3)',
'z-index' : '1000',
'background-color' : 'rgb(111,111,200)'
});
}
clearInterval(timer);
}else{
**document.removeEventListener('touchstart',isScroll);**
//这里的取消事件监听没有效果,一直都处于阻止默认事件,并没有还原
}
},10);
elem.addEventListener('touchmove',touchMove);
elem.addEventListener('touchend',touchEnd);
}