5

How can I disable the offset scrolling for my webapp?

I mean the dark gray area https://i.stack.imgur.com/a3Rt4.png

Disable scrolling in an iPhone web application? I've tried this but it didn't work all the time, it only works sometimes then it suddenly stops and i can scroll again.

Community
  • 1
  • 1
antpaw
  • 15,444
  • 11
  • 59
  • 88

4 Answers4

12
document.body.addEventListener('touchmove', function(e){ e.preventDefault(); });

works, but make sure the body has a 100% height of the screen

antpaw
  • 15,444
  • 11
  • 59
  • 88
  • 1
    Awesome solution but this is disaster if your body height goes beyond the visible edges of your phone. It won't let you scroll vertically or horizontally. – Jay Mayu Jan 22 '13 at 12:34
3

This completely disables all touch-move events.

<script type="text/javascript">
    function blockMove() {
       event.preventDefault() ;
}
</script>

<body ontouchmove="blockMove()">

It freezes your screen in place, giving it a more native feel. But also disables any scrollable areas. If you want to keep your scrollable areas and still remove the rubber band effect at the top and bottom, see here: http://cubiq.org/iscroll.

kaleazy
  • 5,922
  • 2
  • 47
  • 51
0

I wrote this solution for allowing scrollable areas but preventing the body from scrolling when they're visible

https://stackoverflow.com/a/18922984/2009533

Community
  • 1
  • 1
nrutas
  • 4,983
  • 2
  • 16
  • 16
0

The bottom line is that there are a number of ways to achieve this, but none are documented. They all currently rely on searching through subviews of your UIWebView and modifying their properties - all of these subviews are undocumented, so your results may vary. It is certainly not an ideal way to do things, and as you've found out results can be varied. If you can get hold of the scroll view that is contained within the web view (again, undocumented) you can disable the offset scrolling/bouncing - this link may prove helpful:

http://blog.andrewpaulsimmons.com/2010/02/controlling-uiscrollview-in-uiwebview.html

iOS 5 has an official fix for this, but you'd need to ask at devforums.apple.com or read the new documentation, because everything iOS 5 related is still under non-disclosure and can't really be discussed here.

lxt
  • 31,146
  • 5
  • 78
  • 83
  • but thats a objective-c solution right? sencha does it somehow without objective-c in their demos, if im not misstaken. – antpaw Jul 06 '11 at 18:57
  • 1
    I don't know why this answer received a downvote. The fact that you can search through UIWebView's subviews, although obvious in retrospect, was and still is one of the most valuable pieces of knowledge I ever got from StackOverflow. – Dan Abramov Aug 30 '12 at 19:55