Posted By

timothypwalter on 02/02/12


Tagged

scroll safari no iphone ipod touch iPad


Versions (?)

Preventing elastic scrolling on iDevice


 / Published in: JavaScript
 

URL: http://matt.might.net/articles/how-to-native-iphone-ipad-apps-in-javascript/

If you a flick a web app past the bottom or top of the page, the page itself gets elastically tugged away from the URL bar or the button bar (or the bottom/top of the screen if it's in full-screen mode).

This behavior is another giveaway that your app isn't native, and it's rarely the behavior you want in a native app.

To stop this behavior, capture touchmove events on the document in JavaScript and cancel them. You can do this by adding a handler to the body tag, and invoking the preventDefault method on the event object:

  1. <script>
  2. function BlockMove(event) {
  3. // Tell Safari not to move the window.
  4. event.preventDefault() ;
  5. }
  6. </script>
  7.  
  8. <body ontouchmove="BlockMove(event);" >
  9. ...
  10. </body>

Report this snippet  

You need to login to post a comment.