Side navigation
#6446 closed bug (fixed)
Opened April 16, 2010 09:47AM UTC
Closed October 26, 2012 01:44PM UTC
Last modified May 20, 2013 11:17AM UTC
Mobile Safari 4.0.4: $.offset.top() reports wrong position after scroll
Reported by: | matas | Owned by: | |
---|---|---|---|
Priority: | high | Milestone: | 1.9 |
Component: | offset | Version: | 1.4.2 |
Keywords: | iphone, ipad, scroll | Cc: | |
Blocked by: | Blocking: |
Description
demonstration: http://fiddle.jshell.net/G9ZAR/show/light/
source: http://fiddle.jshell.net/G9ZAR
click on the first link, click on the second.
Safari 4.0.5 shows offset().top 390
Mobile Safari 4.0.4 (on iPad) shows offset().top 780
it seems that after vertical scroll, the scrollTop get's added to the actual position.
Attachments (0)
Change History (17)
Changed May 05, 2010 01:13PM UTC by comment:1
Changed May 14, 2010 07:02PM UTC by comment:2
my workaround is
$.browser.mobileSafari = /webkit.*mobile/i.test(navigator.userAgent)
$.fn.cssKluge=function(css){
if ($.browser.mobileSafari){
css.top-=window.scrollY
css.left-=window.scrollX
}
return this.css(css)
}
Changed June 09, 2010 03:31PM UTC by comment:3
thanks jake,
here's my (dirty) take on the override:
what would be a clean solution? probably adding an absolutely positioned element to an iframe, scrolling it and then testing for the offset === position
Changed June 11, 2010 07:09AM UTC by comment:4
Small improvement to previous for old safari versions compatibility:
Changed June 11, 2010 07:12AM UTC by comment:5
Thanks matas for good decision!
Changed October 06, 2010 12:17PM UTC by comment:6
rty I've added an extra test vs iOS version since the bug occurs only on 3.2-4.0.x, 4.1 is not affected. Feel free to add the following test condition to your snipplet:
/; CPU.*OS (?:3_2|4_0)/i.test(navigator.userAgent)
Changed October 15, 2010 01:34AM UTC by comment:7
priority: | → undecided |
---|---|
status: | new → open |
Changed November 03, 2010 10:40PM UTC by comment:8
Just thought I'd add my own little detection JS to the mix. It's a lot smaller than others but relies completely on the user agent string:
Changed November 04, 2010 10:49PM UTC by comment:9
I've found that calculating the offset with straight javascript seems to work. Test page:
http://mark.antsclimbtree.com/files/jquery.ipad-test.php
Clicking the yellow square shows the top and left as calculated by jQuery as well as straight javascript. They should always be the same, but on iOS <4.1 they are not if you scroll anywhere.
So, is this indeed simply a bug in jQuery? Anyway, a workaround that doesn't involve browser detection might be to not use jQuery to calculate the top and left.
Changed November 12, 2010 02:39AM UTC by comment:10
milestone: | 1.4.3 |
---|
Resetting milestone to future.
Changed November 16, 2010 04:22AM UTC by comment:11
For all those using the workaround function hack, you *might* want to test result for null before you start subtracting. (I had some poorly behaved code that happens to call offset and get a null. The workaround function exploded in the same scenario...)
Changed April 17, 2011 06:40PM UTC by comment:12
milestone: | → 1.next |
---|---|
priority: | undecided → high |
Changed September 28, 2011 06:55PM UTC by comment:13
This actually occurs on the desktop as well... test a mobile web-app in Chrome by scrolling and then clicking on your target -- gets the same result as mobile safari.
Changed September 28, 2011 06:58PM UTC by comment:14
"test a mobile web-app in Chrome" any suggestions?
Changed June 05, 2012 11:44PM UTC by comment:15
Reduced Test case that shows the bug in IOS 4.0.2 and others.
Changed October 26, 2012 01:44PM UTC by comment:16
milestone: | 1.next → 1.9 |
---|---|
resolution: | → fixed |
status: | open → closed |
This works in latest http://jsbin.com/ofoqoc/6/edit
Changed May 20, 2013 11:17AM UTC by comment:17
Replying to [comment:1 edwincheese]:
+1 Same issue as reported in JQuery forum: http://forum.jquery.com/topic/offset-returns-incorrect-values-in-ipad
+1 Same issue as reported in JQuery forum: http://forum.jquery.com/topic/offset-returns-incorrect-values-in-ipad