13

I use the following code to disable scrolling in desktop browsers but it doesn't work for iPhone screen resolution.

$("html").css("overflow", "hidden");

What else do I need to add?

Praveen
  • 55,303
  • 33
  • 133
  • 164
Orb Hitter
  • 317
  • 1
  • 4
  • 9

2 Answers2

29
//target the entire page, and listen for touch events
$('html, body').on('touchstart touchmove', function(e){ 
     //prevent native touch activity like scrolling
     e.preventDefault(); 
});

if having the touch event blocked doesn't work for you, you can always go like this:

html, body{
     max-width:100%;
     max-height:100%;
     overflow:hidden;
}
Fresheyeball
  • 29,567
  • 20
  • 102
  • 164
5

I'm gonna provide an a piece that doesn't utilize jQuery so the next "Javascripter" can just copy'n'paste:

var defaultPrevent=function(e){e.preventDefault();}
document.body.parentElement.addEventListener("touchstart", defaultPrevent);
document.body.parentElement.addEventListener("touchmove" , defaultPrevent);
document.body.addEventListener("touchstart", defaultPrevent);
document.body.addEventListener("touchmove" , defaultPrevent);
CyberFox
  • 780
  • 6
  • 24