0
votes

I have been working on rather simple webkit transforms to create (layman's) animations. I'm doing pretty good except for one issue, on which I'm yet to find some info. Here goes:

Description: I have a rectangular div, that I rotate by 90 degrees, using target.style.webkitTransform += 'rotateZ(90deg)'; which is fine - and I translate it using target.style.webkitTransform += 'translate3d(50px, 0px, 0px)';

Problem: When you rotate, the axis of the element also rotates and if you translate (for example) in x-axis, the object will move in the new direction (that the element is facing towards) e.g. 50 px downwards in the example above (after the rotation).

I need a way to recalculate/reset the axis (without changing the rotation) so that the animation makes sense for a lay man i.e. For programmers it's easy to see that the object is facing in a different direction but for non-techie user left will always remain left.

The requirement: When the user says move it 50px on x-axis it should move 50px on x-axis (for the user) regardless of rotation or any other transform applied to it beforehand.

Further: I'll not know in advance how the user will manipulate an object hence I can't take fixed values and work around them, hence the need for a formula to recalculate/reset everything given the object's style properties and construct further transforms.

1
Couldn't you move the element with top and left properties (and position absolute or relative) ? - Golmote Kinoko
That's not an option for two reasons: 1- I don't want to mess with top and left for I will be giving options to slide the element back in as well. In which case I can either store initial position and last position for each transform or I just work with offset positions. 2- using left and top properties results in jerky animations on devices, transforms are way smoother - more so when you have many elements of relatively larger sizes. - Ballack

1 Answers

0
votes

If you're appending the translate() to the end of the transform, then it should translate by exactly what you specified, independent of any previous rotations.