diff options
author | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2019-01-18 19:52:12 +0100 |
---|---|---|
committer | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2019-01-18 19:52:12 +0100 |
commit | 4cfcc9a7f9f61406c565e24b87d4cc83cc9a1ccf (patch) | |
tree | 59bb9425e98eb103fcdb17152d85a56f1a993c7f /src/types | |
parent | ef03ef8218ce36a994a94d5b8b6d87ff9151b606 (diff) | |
download | svg.js-4cfcc9a7f9f61406c565e24b87d4cc83cc9a1ccf.tar.gz svg.js-4cfcc9a7f9f61406c565e24b87d4cc83cc9a1ccf.zip |
speed up zoom function for non-FF Browser
Diffstat (limited to 'src/types')
-rw-r--r-- | src/types/Box.js | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/src/types/Box.js b/src/types/Box.js index 90979d2..190d60d 100644 --- a/src/types/Box.js +++ b/src/types/Box.js @@ -159,30 +159,32 @@ registerMethods({ }, zoom (level, point) { - var style = window.getComputedStyle(this.node) - - var width = parseFloat(style.getPropertyValue('width')) - - var height = parseFloat(style.getPropertyValue('height')) - - var v = this.viewbox() - - var zoomX = width / v.width - - var zoomY = height / v.height + let width = this.node.clientWidth + let height = this.node.clientHeight + const v = this.viewbox() + + // Firefox does not support clientHeight and returns 0 + // https://bugzilla.mozilla.org/show_bug.cgi?id=874811 + if (!width && !height) { + var style = window.getComputedStyle(this.node) + width = parseFloat(style.getPropertyValue('width')) + height = parseFloat(style.getPropertyValue('height')) + } - var zoom = Math.min(zoomX, zoomY) + const zoomX = width / v.width + const zoomY = height / v.height + const zoom = Math.min(zoomX, zoomY) if (level == null) { return zoom } - var zoomAmount = zoom / level + let zoomAmount = zoom / level if (zoomAmount === Infinity) zoomAmount = Number.MIN_VALUE point = point || new Point(width / 2 / zoomX + v.x, height / 2 / zoomY + v.y) - var box = new Box(v).transform( + const box = new Box(v).transform( new Matrix({ scale: zoomAmount, origin: point }) ) |