Reputation: 705
Interesting question:
How to disable scroll on mobile device BUT in code no need to check mobile browser o etc.
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.
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]);
}
}
Upvotes: 1
Views: 687
Reputation: 705
Solution is:
$('body').bind('touchmove', function(e){e.preventDefault()});
$("body").unbind("touchmove");
Upvotes: 1