有趣的问题:
如何禁用移动设备上的滚动,但在代码中不需要检查移动浏览器等。
我在写移动版的网站。在网页浏览器中,我的功能运行良好!
当我叫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]);
}
}发布于 2016-04-20 13:24:18
解决方案是:
$('body').bind('touchmove', function(e){e.preventDefault()});
$("body").unbind("touchmove"); https://stackoverflow.com/questions/36744599
复制相似问题