[英]How to disable scroll on mobile browser without checking device?
Interesting question:有趣的问题:
How to disable scroll on mobile device BUT in code no need to check mobile browser o etc.如何在移动设备上禁用滚动但在代码中无需检查移动浏览器 o 等。
I'm writing mobile version of web site.我正在编写网站的移动版本。 In web browser my function works well!
在网络浏览器中,我的功能运行良好!
When i calling Scroll("off); it's stops. But on mobile device (ios) i still can touchmoving content.当我调用 Scroll("off); 它停止。但在移动设备 (ios) 上我仍然可以触摸移动内容。
Can someone help to modify function for this case?有人可以帮助修改这种情况下的功能吗? Result must be: No scroll on web, NO touching moves on mobile device.
结果必须是:在网络上没有滚动,在移动设备上没有触摸移动。
Here what i have:这是我所拥有的:
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]);
}
}
Solution is:解决办法是:
$('body').bind('touchmove', function(e){e.preventDefault()});
$("body").unbind("touchmove");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.