Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript touchstart上的preventDefault(),而不禁用滚动_Javascript_Jquery_Scroll_Touchstart - Fatal编程技术网

Javascript touchstart上的preventDefault(),而不禁用滚动

Javascript touchstart上的preventDefault(),而不禁用滚动,javascript,jquery,scroll,touchstart,Javascript,Jquery,Scroll,Touchstart,我使用以下脚本阻止第一次点击链接: $(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; }

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

$(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();
        }
    });
});
因为这些链接[#容器a]覆盖了整个屏幕,我无法在触摸设备上滚动

如果用户滚动(touchmove/swipe/drag/…),是否有办法保持滚动行为正常?


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

我找到了解决此问题的另一种方法,使用此库将处理点击事件而不影响滚动功能 代码如下所示

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