【问题标题】:preventDefault() on touchstart without disabling scrolling在不禁用滚动的情况下在 touchstart 上进行 preventDefault()
【发布时间】:2013-02-07 01:04:33
【问题描述】:

我使用以下脚本来防止第一次点击链接:

$(document).ready(function () {
    $('#container a').bind("touchstart",function(e){
        var $link_id = $(this).attr('id');
        if ($(this).parent().parent().data('clicked') == $link_id) {
            return true;
        } else {
            e.preventDefault();
        }
    });
});

因为这些链接 [#container a] 覆盖了整个屏幕,我无法在触控设备上滚动。

如果用户滚动(touchmove / swipe / drag / ...),有没有办法让滚动行为保持正常?

也许还有另一种方法/脚本可以在不禁用滚动的情况下获得我想要的效果...?

【问题讨论】:

    标签: javascript jquery scroll touchstart


    【解决方案1】:

    我通过使用quo.js 找到了解决此问题的另一种方法@ 这个库将处理点击事件而不影响滚动功能 代码会是这样的

    $(document).ready(function () {
     $$('#container a').tap(function(){
         //your function here
     });
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-06-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-07
      • 1970-01-01
      • 2018-08-02
      相关资源
      最近更新 更多