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

时间:2016-04-20 12:59:31

标签: javascript jquery jquery-mobile

有趣的问题:

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

我正在撰写移动版网站。在网络浏览器中,我的功能运作良好!

当我打电话给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]);
      }
    }

1 个答案:

答案 0 :(得分:1)

解决方案是:

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