[英]How to disable scroll on mobile browser without checking device?
有趣的问题:
如何在移动设备上禁用滚动但在代码中无需检查移动浏览器 o 等。
我正在编写网站的移动版本。 在网络浏览器中,我的功能运行良好!
当我调用 Scroll("off); 它停止。但在移动设备 (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");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.