Skip to content

Instantly share code, notes, and snippets.

@iros
Created March 24, 2013 02:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iros/5230224 to your computer and use it in GitHub Desktop.
Save iros/5230224 to your computer and use it in GitHub Desktop.
transform svg element around its center
// transform around center:
// formula: matrix(sx, 0, 0, sy, cx-sx*cx, cy-sy*cy)
var b = el.getBBox();
var center = [b.x + b.width/2, b.y + b.height/2];
var factor = 1.8;
el.attr('transform','matrix(' + factor + ', 0, 0, ' + factor + ', ' +
(center[0] - factor * center[0]) +
',' + (center[1] - factor * center[1])+')');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment