For anyone who is experiencing this problem using Ariel Flesler's LocalScroll plugin, Arief's answer above works and can be applied in the following way:
$(document).ready(function() {
$.localScroll.defaults.axis = 'x';
$.localScroll({
target:'#content',
onAfter:function(){
var xPos = window.pageXOffset;
var $fixedElement = $('#menubar');
$fixedElement.css({ "position": "absolute" });
window.scroll(xPos,0);
$fixedElement.css({ "position": "fixed" });
}
});
});
In this case, I have a horizontally scrolling website (hence defaulting to the 'x' axis - yours may be different). I am scrolling a '#content' div which is set to 'overflow:hidden' (hence the 'target'). And then all of Arief's magic is in the 'onAfter:function'.
I have tweaked this so that instead of 'window.scroll(0,0)' - which scrolls back to the very beginning of the page - it gets the current window scroll position by using the window.pageXOffset and sets a variable "xPos" for this (again, if you are scrolling on the Y axis, or even both, you may need to use window.pageYOffset also). This variable is then used in the 'window.scroll(xPos,0)' - mine is "0" on the y axis, as am not scrolling on that axis. I believe there may be different ways of calculating current scroll position, but this worked best for me.
I initially couldn't make this work when my 'overflow:hidden' element was actually the html tag, so moved this to the '#content' div and it worked just fine. I have been testing on iPad 3 so don't know how bacwards compatible it is.