jquery - 无意中停止触摸端触发链接

标签 jquery ios touch-event

我正在使用 touchend 事件来防止 ios 需要两次触摸才能触发 href 链接。 这工作正常,但它在滚动时无意中触发了链接。

我知道解决方案是实现 touchstart 以查看是否有移动,但我是 jquery 新手,我不确定如何应用它。

这是touchend代码

$('a').on('touchend', function(e) {
var el = $(this);
var link = el.attr('href');
window.location = link;
});

希望有人能帮忙。

谢谢

最佳答案

好的,这就是我使用 this post 中的代码解决此问题的方法

var dragging = false;
$("a").on("touchmove", function(){
  dragging = true;
});

$("a").on("touchend", function(e){
  if (dragging){
e.preventDefault();
}
else {var el = $(this);
var link = el.attr('href');
window.location = link;
}    

});

$("a").on("touchstart", function(){
dragging = false;
});

这对我有用。

关于jquery - 无意中停止触摸端触发链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22451908/

相关文章:

ios - 使用 MFMailComposeViewControllerDelegate EXE_BAD_ACCESS 出错(代码=1,地址=0x8)

ios - 如何以编程方式将触摸事件伪造到 UIButton?

javascript - 自动完成中的数组不显示任何内容

javascript - jQuery:删除和重新添加类

ios - 将 modalPresentationStyle 设置为自定义会导致 MFMailComposeViewController 中的状态栏颜色错误

ios - UIViewAutoresizing flexible Height+Top 或 Height+Bottom 何时有意义?它有什么作用?

swift - 覆盖 UIGestureRecognizer touchesBegan

android - OnTouch 位图覆盖

javascript - 如何隐藏columnSelection中的列?

javascript - 如何添加专门针对IE10的CSS Hack?