svgdotjs / svg.js

The lightweight library for manipulating and animating SVG
https://svgjs.dev
Other
11.14k stars 1.08k forks source link

where is the center of image rotate with dx()、dy() operation? #1095

Closed alexer2019 closed 4 years ago

alexer2019 commented 4 years ago

var draw = SVG('drawing').size(300, 300).addClass('svg'); var image = draw.image('image/emptyCar.png').size(32, 32).move(0,0); image.animate().dx(100); image.animate(1000, '-').rotate(90,100+16,16); image.animate().dx(200); image.animate(1000, '-').rotate(90,?,?);

question: where is the ?,? will be???? I am refused...

alexer2019 commented 4 years ago

I want to rotate the image by its center

Fuzzyma commented 4 years ago

Get the bbox of the image by calling bbox() (and getting .cx and .cy of it) and use that. Or just do the math. You moved by 300x so the center is probably at 150 + 16x