#5517 closed bug (invalid)
.offset().top gives incorrect values
Reported by: | rene___ | Owned by: | rene___ |
---|---|---|---|
Priority: | undecided | Milestone: | 1.4 |
Component: | offset | Version: | 1.3.2 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
I use the code below to get the optimum scrolltop position for a comment, so the comment will be scrolled to the center of the window (div).
function getDivScrollTop(Div) {
var Comments = $('#comments'); var Comment = $(Div); var Top = Comment.offset().top; var Sibling = Comment.next(); var ViewportHeight = parseInt(Comments.css('height')); var NewTop = Top - ((ViewportHeight - (Sibling.offset().top-Top)) / 2); if (NewTop > Top) {
NewTop = Top - (ViewportHeight / 4);
} return NewTop;
}
But since I changed it from:
Comments[0].offsetTop too Comments.offset().top, it alternates in right values and then completely wronge values.
I attached a screencapture from IE7's debuggers watches window.
I also tested it with the latest version of Chrome, and the problem is the same.
Attachments (1)
Change History (5)
Changed 13 years ago by
Attachment: | offsettop.png added |
---|
comment:1 Changed 13 years ago by
Another issue which I think is related to offset().top under IE 7&8. For example - I have an element in an IFrame which I want to position absolutely. When scrolling the whole frame offset().top still returns one and the same position. I've fixed it with adding the scrollTop distance.
//only for IE function getOffset(element) { var offset = $(element).offset(); var top = offset.top; var left = offset.left; var isInIFrame = (window.location != window.parent.location) ? true : false; if (isInIFrame && $.browser.msie && document.documentElement) { if (document.documentElement.scrollTop) { top += document.documentElement.scrollTop; } if (document.documentElement.scrollLeft) { left += document.documentElement.scrollLeft; } } return {top:top, left:left}; }
Under FF and Chrome there is no such problem.
comment:2 Changed 12 years ago by
Owner: | changed from brandon to rene___ |
---|---|
Status: | new → pending |
Please provide a reduced test case demonstrating this issue on jsFiddle.
comment:3 Changed 12 years ago by
Resolution: | → invalid |
---|---|
Status: | pending → closed |
Because we get so many tickets, we often need to return them to the initial reporter for more information. If that person does not reply within 14 days, the ticket will automatically be closed, and that has happened in this case. If you still are interested in pursuing this issue, feel free to add a comment with the requested information and we will be happy to reopen the ticket if it is still valid. Thanks!
comment:4 Changed 10 years ago by
Thanks for your getOffset function above. This worked perfectly for us!
Debuggers watch view of the values monitored, while breaking the getDivScrollTop function