Created
November 3, 2010 22:38
-
-
Save Craga89/661844 to your computer and use it in GitHub Desktop.
Fixes the jQuery.fn.offset() function in iOS to correct for fixed positioning issues (v3.1-4.0, v4.3-4.3.3)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
var iOS = parseFloat( | |
('' + (/CPU.*OS ([0-9_]{1,5})|(CPU like).*AppleWebKit.*Mobile/i.exec(navigator.userAgent) || [0,''])[1]) | |
.replace('undefined', '3_2').replace('_', '.').replace('_', '') | |
) || FALSE; | |
if((iOS > 3.1 && iOS < 4.1) || (iOS >= 4.3 && iOS < 4.33)){ | |
$.fn._oldOffset = $.fn.offset; | |
$.fn.offset = function() { | |
var result = $.fn._oldOffset.call(this); | |
result.top -= window.scrollY; | |
result.left -= window.scrollX; | |
return result; | |
} | |
} | |
}()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if( parseFloat(((/CPU.+OS ([0-9_]{3}).*AppleWebkit.*Mobile/i.exec(navigator.userAgent)) || [0,'4_2'])[1].replace('_','.')) < 4.1) { | |
$.fn.Oldoffset = $.fn.offset; | |
$.fn.offset = function() { | |
var result = $(this).Oldoffset(); | |
result.top -= window.scrollY; | |
result.left -= window.scrollX; | |
return result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Fix update
The current version of iOS (~8.x) has the issues too, so we could fix it by updating the snippet:
Resources