Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/73.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 如何在不检查设备的情况下禁用移动浏览器上的滚动?_Javascript_Jquery_Jquery Mobile - Fatal编程技术网

Javascript 如何在不检查设备的情况下禁用移动浏览器上的滚动?

Javascript 如何在不检查设备的情况下禁用移动浏览器上的滚动?,javascript,jquery,jquery-mobile,Javascript,Jquery,Jquery Mobile,有趣的问题: 如何禁用移动设备上的滚动,但在代码中无需检查移动浏览器o等 我在写移动版的网站。在web浏览器中,我的功能运行良好 当我呼叫Scroll(“关闭”)时,它会停止。但在移动设备(ios)上,我仍然可以触摸移动内容 有人可以帮助修改这种情况下的功能吗?结果必须是:在网络上没有滚动,在移动设备上没有触摸移动 以下是我所拥有的: function Scroll(str) { var scrollPosition = [ self.pageXOffset

有趣的问题:

如何禁用移动设备上的滚动,但在代码中无需检查移动浏览器o等

我在写移动版的网站。在web浏览器中,我的功能运行良好

当我呼叫Scroll(“关闭”)时,它会停止。但在移动设备(ios)上,我仍然可以触摸移动内容

有人可以帮助修改这种情况下的功能吗?结果必须是:在网络上没有滚动,在移动设备上没有触摸移动

以下是我所拥有的:

function Scroll(str)
    {
      var scrollPosition = [
        self.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft,
        self.pageYOffset || document.documentElement.scrollTop  || document.body.scrollTop
      ];

      if(str=="off")
      {
        var html = jQuery("html");
        html.data("scroll-position", scrollPosition);
        html.data("previous-overflow", html.css("overflow"));
        html.css("overflow", "hidden");
        window.scrollTo(scrollPosition[0], scrollPosition[1]);
      }
      else
      {
        var html = jQuery("html");
        var scrollPosition = html.data("scroll-position");
        html.css("overflow", html.data("previous-overflow"));
        window.scrollTo(scrollPosition[0], scrollPosition[1]);
      }
    }

解决方案是:

$('body').bind('touchmove', function(e){e.preventDefault()}); 
$("body").unbind("touchmove");