Here's what I do - this solution prevents the background from scrolling while maintaining its original position (i.e. it does not go to the beginning).
preventScroll : function(prevent) { var body = $('body'), html = $('html'), scroll; if (prevent) { var width = body.css('width'); scroll = window.pageYOffset; // This is all you need to do to prevent scroll on everything except iOS. html.css({ 'overflow': 'hidden'}); // For iOS, change it to fixed positioning and make it in the same place as // it was scrolled. // For all systems, change max-width to width; this prevents the page getting // wider when the scrollbar disappears. body.css({ 'position': 'fixed', 'top': -scroll, 'max-width' : width}); } else { scroll = -parseInt(body.css('top')); html.css({ 'overflow': '' }); body.css({ 'position': '', 'top': '', 'max-width': '' }); window.scrollTo(0, scroll); } },
This will cause problems when resizing (turning the phone) while scrolling; I also have a resize event that triggers preventScroll (false) and then preventScroll (true) to update the position in this case.
source share