html - Scale an SVG element using a transform origin -
<html lang="en-us"> <head> <link rel="stylesheet" href="https://codepen.io/basement/pen/oepkxy.css"> </head> <body> <iframe src="https://s.codepen.io/basement/debug/zdpvyv/pnavylzmjrqr"></iframe> <div class="wrp"> <svg xmlns="http://www.w3.org/2000/svg" viewbox="0 0 100 100" width="100" height="100" class="canvas" > <defs> <style type="text/css"> polygon { fill: none; stroke-width: 0.5; stroke: #f00; } </style> </defs> <g transform="translate( 0 12.5 ) scale( 1 )"> <polygon points=" 75,6.7 75,93.3 0,50 " transform="rotate( -30 50 50 )" /> </g> </svg> </div> <script src="origin.js"></script> </body> </html>
i want make red triangle in snippet above scale larger while defining specific transform origin. rotate attribute in svg can this:
transform="rotate( -30 50 50 )"
the first value: -30
rotates element counter-clockwise. 50 50
defines transform origin ( x , y respectively ). can scale
?. want red triangle scale keep it's origin centered.
note: i know transform-origin
in css i'm assuming coordinate system css uses relative whole web page or it's closest positioned element is... want define in svg coordinate terms done rotate property.
you can translate --> scale --> translate_back e.g.
<g transform="translate( 0 12.5 ) translate( 50 50) scale( 1.5 ) translate( -50 -50)">
explanation: assuming use (50 50) scale origin, first translate shape (-50, -50) desired scale origin @ (0, 0). scale, , reverse translation put shape were.
Comments
Post a Comment