diff options
author | bryhoyt <bryan@brush.co.nz> | 2014-06-12 13:27:33 +1200 |
---|---|---|
committer | bryhoyt <bryan@brush.co.nz> | 2014-06-12 13:27:33 +1200 |
commit | ff6089410a03acda00fb8cb2f09ed94d7228dd4c (patch) | |
tree | 02dddd2bdfe142d366499f5b448a5a67940fa4ba | |
parent | e3a0f3a887a398a87356f63253830e1baf67823e (diff) | |
download | svg.js-ff6089410a03acda00fb8cb2f09ed94d7228dd4c.tar.gz svg.js-ff6089410a03acda00fb8cb2f09ed94d7228dd4c.zip |
Offset rbox by window scroll, because getBoundingClientRect changes when window is scrolled
As per https://developer.mozilla.org/en-US/docs/Web/API/Element.getBoundingClientRect "If this is not the desired behaviour just add the current scrolling position to the top and left property (via window.scrollX and window.scrollY) to get constant values independent from the current scrolling position."
-rwxr-xr-x | src/rbox.js | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/rbox.js b/src/rbox.js index 30779a4..54e08cb 100755 --- a/src/rbox.js +++ b/src/rbox.js @@ -46,6 +46,10 @@ SVG.RBox = function(element) { this.width = box.width /= zoom this.height = box.height /= zoom + /* offset by window scroll position, because getBoundingClientRect changes when window is scrolled */ + this.x += window.scrollX; + this.y += window.scrollY; + /* add center, right and bottom */ boxProperties(this) @@ -69,4 +73,4 @@ SVG.extend(SVG.RBox, { return b } -})
\ No newline at end of file +}) |