问题:
SomeDomElement.addEventListener('touchstart', function preventLongPress(event) {
if (event.touches.length >=1) event.preventDefault();
}, false);如果我使用:if (event.touches.length >=1) event.preventDefault();,那么这将防止长按事件,但也会禁用滚动事件。
对于长新闻,没有touchmove或touchend事件。
我想要的:
防止长按压,但不要阻止滚动
Note :我只使用香草Javascript,不使用jQuery
发布于 2018-10-24 11:44:57
希望这能帮到你。
document.addEventListener("touchstart", function(){
detectTap = false;
});
document.addEventListener("touchmove", function(){
detectTap = true;
});
document.addEventListener("touchend", function(){
if(detectTap)
alert("scrolled"); /* here add whatever functionality you wants */
else
alert("long pressed"); /* here add whatever functionality you wants */
});https://stackoverflow.com/questions/52967597
复制相似问题