-
-
Save rty/434145 to your computer and use it in GitHub Desktop.
// small fix for old safari versions compatibility | |
// this bug occures | |
// on iPhone OS since 3.2 version (iPad) | |
// and on iOS since 4.0 version | |
// 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) | |
&& "getBoundingClientRect" in document.documentElement) { | |
(function ($) { | |
$.fn.offsetOld = $.fn.offset; | |
$.fn.offset = function () { | |
var result = this.offsetOld(); | |
result.top -= window.scrollY; | |
result.left -= window.scrollX; | |
return result; | |
}; | |
})(jQuery); | |
} |
works perfectly for me, thank you!
This seems to be fixed in iOS 4.1 -I can only repro now on an iPad (still on iOS 3.2), so I had to change the regex to the following:
/ipad.*webkit.*mobile/i.test(navigator.userAgent)
iOS 4.2 should hopefully fix this issue for iPads as well...
I think it has been fixed in iOS 4.1 version for iPhone. Starting from iOS 4.2 it could be installed to both iPhone and iPad. My solution is:
if (/webkit.mobile/i.test(navigator.userAgent)
&& "getBoundingClientRect" in document.documentElement
&& parseFloat(/OS (.) like/ig.exec(navigator.userAgent)[1].replace('_', '.')) < 4.1) {
(function ($) {
$.fn.offset = function () {
var result = this.offsetOld();
result.top -= window.scrollY;
result.left -= window.scrollX;
return result;
};
})(jQuery);
};
Thanks, man -I was working on something similar, but you beat me to it. I realized after I posted I didn't account for people who are on an old version of the OS. I ended up with this:
if (/webkit.*mobile/i.test(navigator.userAgent) && parseFloat($.browser.version) < 532.9 && "getBoundingClientRect" in document.documentElement) {
...
}
I think it'll be slightly faster than the RegEx.
Yeah! It's cool solution:)
Awesome, thanks so much for putting this together; I'm using it on 3rd Row.