Bug Tracker

Modify

Ticket #5517 (closed bug: invalid)

Opened 4 years ago

Last modified 15 months ago

.offset().top gives incorrect values

Reported by: rene___ Owned by: rene___
Priority: undecided Milestone: 1.4
Component: offset Version: 1.3.2
Keywords: Cc:
Blocking: Blocked by:

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

offsettop.png Download (19.4 KB) - added by rene___ 4 years ago.
Debuggers watch view of the values monitored, while breaking the getDivScrollTop function

Change History

Changed 4 years ago by rene___

Debuggers watch view of the values monitored, while breaking the getDivScrollTop function

comment:1 Changed 4 years ago by antipop2

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 3 years ago by snover

  • Owner changed from brandon to rene___
  • Status changed from new to pending

Please provide a reduced test case demonstrating this issue on  jsFiddle.

comment:3 Changed 2 years ago by trac-o-bot

  • Status changed from pending to closed
  • Resolution set to invalid

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!

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.