Skip to content

Commit

Permalink
Fixed the offset calculation in when scrolling
Browse files Browse the repository at this point in the history
Therefore added a new function getAncestorOffset()
  • Loading branch information
SebastianZ committed May 28, 2013
1 parent 5de315f commit 572fabc
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions extension/content/firebug/lib/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,11 @@ Dom.findPrevious = function(node, criteria, downOnly, maxRoot)
// ********************************************************************************************* //
// Graphics

/**
* Gets the absolute offset of an element
* @param {Element} elt Element to get the info for
* @returns {Object} x and y offset of the element
*/
Dom.getClientOffset = function(elt)
{
function addOffset(elt, coords, view)
Expand Down Expand Up @@ -505,6 +510,25 @@ Dom.getLTRBWH = function(elt)
return dims;
};

/**
* Gets the offset of an element relative to an ancestor
* @param {Element} elt Element to get the info for
* @param {Element} ancestor Ancestor element used as origin
*/
Dom.getAncestorOffset = function(elt, ancestor)
{
var offset = {x: 0, y: 0};
var offsetParent = elt;
do
{
offset.x += offsetParent.offsetLeft;
offset.y += offsetParent.offsetTop;
offsetParent = offsetParent.offsetParent;
} while (offsetParent && offsetParent !== ancestor);

return offset;
};

/**
* Gets the offset size of an element
* @param {Object} elt Element to move
Expand Down Expand Up @@ -649,10 +673,7 @@ Dom.scrollTo = function(element, scrollBox, alignmentX, alignmentY, scrollWhenVi
if (!scrollBox)
return;

var offset = {
x: element.offsetLeft,
y: element.offsetTop
};
var offset = Dom.getAncestorOffset(element, scrollBox);

if (!alignmentX)
alignmentX = "centerOrLeft";
Expand Down

0 comments on commit 572fabc

Please sign in to comment.