Skip to content

Commit

Permalink
Fix for zoom offset on SVG elements
Browse files Browse the repository at this point in the history
  • Loading branch information
Joel Steres committed Jun 17, 2017
1 parent 0ac4605 commit f89c15c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/placementcalculator.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,10 @@ function PlacementCalculator() {
}
}

return {
return compensateForZoomBug({
top: coords.y + session.scrollTop,
left: coords.x + session.scrollLeft
};
});
}

// expose methods
Expand Down
19 changes: 13 additions & 6 deletions src/utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,13 +236,20 @@ function activateChromeZoomedOffsetPatch() {
* @return {Offsets} The top, left offsets relative to the document.
*/
function getCompensatedOffset(element) {
return compensateForZoomBug(element.offset());
}

/**
* Compensate for the Chrome measurement bug when zoomed.
* @param {object} coords Coordinates to compensate for if zoomed on chrome
* @return {Offsets} The top, left offsets relative to the document.
*/
function compensateForZoomBug(coords) {
if (session.chromePatchRefElement) {
var offset = element.offset();
var r = session.chromePatchRefElement.offset();
return {
left: offset.left - r.left,
top: offset.top - r.top
};
coords.top -= r.top;
coords.left -= r.left;
return coords;
}
return element.offset();
return coords;
}

0 comments on commit f89c15c

Please sign in to comment.