移动端解决手指误触a链接发生跳转行为
移动端解决误触的问题
在移动端用手指滑动时有时会误触a连接,发生跳转,所以需要一个跳转方案来避免误触
//移动端a标签的跳转方案 解决误触
var aNodes = document.querySelectorAll("a");
for(var i=0; i<aNodes.length; i++){
aNodes[i].addEventListener("touchstart",function(){
this.isMoved=false;
})
aNodes[i].addEventListener("touchmove",function(){
this.isMoved=true;
})
aNodes[i].addEventListener("touchend",function(){
//如果误触了,isMoved为true,不会执行跳转
if ( !this.isMoved ) {
location.href=this.href;
}
})
}