Webkit 转换,旋转后翻译
我一直致力于相当简单的 webkit 转换来创建(外行的)动画。我做得很好,除了一个问题,我还没有找到一些信息。这里是:
描述:我有一个矩形 div,我使用 target.style.webkitTransform += 'rotateZ(90deg)' 将其旋转 90 度;这很好 - 我使用 target.style.webkitTransform += 'translate3d(50px, 0px, 0px)'; 翻译它
问题:当您旋转时,元素的轴也会旋转,如果您在 x 轴上平移(例如),对象将沿新方向移动(元素面向的方向),例如在上面的示例中向下 50 px (旋转后)。
我需要一种方法来重新计算/重置轴(不改变旋转),以便动画对于外行来说有意义,即对于程序员来说,很容易看到对象面向不同的方向,但对于非技术用户来说,左边会始终保持左侧。
要求:当用户说在 x 轴上移动 50px 时,它应该在 x 轴上移动 50px(对于用户),无论旋转或事先应用到它的任何其他变换如何。
此外:我不会提前知道用户将如何操作对象,因此我无法采用固定值并解决它们,因此需要一个公式来重新计算/重置给定对象的样式属性的所有内容并构造进一步的转换。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您将
translate()
附加到转换的末尾,那么它应该完全按照您指定的方式进行转换,而与任何先前的旋转无关。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.