Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mataspetrikas/431639 to your computer and use it in GitHub Desktop.
Save mataspetrikas/431639 to your computer and use it in GitHub Desktop.
fix jQuery.offset() in Mobile Safari (iPad, iPhone)
// as of 1.4.2 the mobile safari reports wrong values on offset()
// http://dev.jquery.com/ticket/6446
// remove once it's fixed
if ( /webkit.*mobile/i.test(navigator.userAgent)) {
(function($) {
$.fn.offsetOld = $.fn.offset;
$.fn.offset = function() {
var result = this.offsetOld();
result.top -= window.scrollY;
result.left -= window.scrollX;
return result;
};
})(jQuery);
}
@jonesmac
Copy link

I think this is still an issue today. I found wrapping it in a timeout solved it which tells me that even if document.ready has fired...mobile safari is still laying things out and getting wrong calculations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment