Last active
February 28, 2020 21:30
-
-
Save innermond/e5750af0da6a8bef9b411f33e9574d01 to your computer and use it in GitHub Desktop.
svg element scales arround its center
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$img = document.querySelector('image:nth-of-type(2)') | |
$svg = document.querySelector('svg') | |
k = 2.5 | |
bb = $img.getBBox() | |
x = bb.x + bb.width/2 | |
x *= (1-k) | |
y = bb.y + bb.height/2 | |
y *= (1-k) | |
tsf = $svg.createSVGTransform() | |
tsf.setScale(k,k) | |
trans = $svg.createSVGTransform() | |
trans.setTranslate(x, y) | |
lst = $img.transform.baseVal | |
lst.appendItem(trans) | |
lst.appendItem(tsf) | |
lst.consolidate() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment