Resetting scroll with jQuery freezes iOS

Listening to the scroll event with jQuery and resetting the scroll with window.scrollTo triggers a new scroll event on iOS. That of course resets the scroll again and trigger a new event and so on and so on… So don’t do this:

$(window).on("scroll",function(e){
e.preventDefault();
window.scrollTo(0,0);
});

Here’s a jsFiddle to demonstrate it:

http://jsfiddle.net/GbPF2/2/

Open the result window directly in your mobile:

http://fiddle.jshell.net/GbPF2/2/show/

A simple CSS should do the trick:


html,body{
 width:100%;
 height:100%;
 overflow:hidden;
}

But changing the orientation of the device eventually caused the content to scroll mysteriously, so I added a simple JS to prevent scrolling. It worked on all other platforms.