Created
August 31, 2015 13:31
-
-
Save brunnolou/cab8c0a481ea78ff50dc to your computer and use it in GitHub Desktop.
Calculate SVG absolute `transform-origin` position to be compatible with firefox
This file contains 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
var element = document.querySelector(prompt('Insert the querySelector to the svg element.', '#gear')); | |
var bbox = element.getBBox(), | |
x = bbox.x, | |
y = bbox.y, | |
w = bbox.width, | |
h = bbox.height | |
; | |
var result = | |
'center center' + "\n" + | |
(x + (w / 2)) + 'px ' + | |
(y + (h / 2)) + 'px;' + | |
"\n" + | |
"\n" + | |
'top left' + "\n" + | |
x + 'px ' + | |
y + 'px;' + | |
"\n" + | |
"\n" + | |
'top right' + "\n" + | |
(x + w) + 'px ' + | |
y + 'px;' + | |
"\n" + | |
"\n" + | |
'bottom right' + "\n" + | |
(x + w) + 'px ' + | |
(y + h) + 'px;' + | |
"\n" + | |
"\n" + | |
'bottom left' + "\n" + | |
x + 'px ' + | |
(y + h) + 'px;' + | |
"\n" | |
; | |
alert(result); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To use this:
querySelector
to the SVG elementtransform-origin