daybrush / moveable

Moveable! Draggable! Resizable! Scalable! Rotatable! Warpable! Pinchable! Groupable! Snappable!
https://daybrush.com/moveable/
MIT License
9.93k stars 616 forks source link

Rotatable: setting the center of rotation #705

Open miina opened 2 years ago

miina commented 2 years ago

Environments

Description

Is it possible to change the center of the rotation? For example if instead of rotating around the center of the target, I'd like to rotate the element around a point [x, y] within the element?

daybrush commented 2 years ago

@miina

you can use setFixedDirection on rotateStart

https://daybrush.com/moveable/storybook2/?path=/story/advanced-rotatable--rotate-with-custom-origin

miina commented 2 years ago

@miina

you can use setFixedDirection on rotateStart

https://daybrush.com/moveable/storybook2/?path=/story/advanced-rotatable--rotate-with-custom-origin

Ah, thank you, I saw the storybook in the code for it but didn't find the story for some reason, wasn't sure it was for that. Does setFixedDirection use pixels as unit? Or looking at the code perhaps values from -1 to 1 where [0, 0] is the center, [-1, -1] is the left top?

daybrush commented 2 years ago

@miina

Since it is a direction, it is determined according to the direction and is relative to offsetWidth and offsetHeight.

[0, 0] is center [-1, -1] left, top [1, -1] right top [-1, 1] left bottom [1, 1,] right bottom

ngocducdim commented 1 year ago

@daybrush

Since it is a direction, it is determined according to the direction and is relative to offsetWidth and offsetHeight.

[0, 0] is center [-1, -1] left, top [1, -1] right top [-1, 1] right bottom [1, 1,] right bottom

[-1, 1] right bottom is it suppose to be left bottom?

daybrush commented 1 year ago

@ngocducdim

right. my typo