有趣的问题:
如何在移动设备上禁用滚动,但在代码中无需检查移动浏览器等。
我正在编写网站的移动版本。在网络浏览器中我的功能运行良好!
当我调用 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");
关于javascript - 如何在不检查设备的情况下禁用移动浏览器上的滚动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36744599/