CSS3 变换:如何撤消变换操作?
我想对
应用翻译转换,然后能够将该
返回到其原始位置。对负值应用相同的操作不会将 DIV 返回到屏幕中的原始位置:
应用翻译:
-webkit-transform:translate(300px, 400px);
不起作用的“撤消”效果:
-webkit-transform:翻译(-300px, -400px);
我想要控制撤消级别,因此重置变换不是一个选项。
I want to apply a translate transformation to a <div>
, and then be able to return that <div>
to its original place.
Applying the same operation with negated values doesn't return the DIV to the original place in the screen:
Applied translation:
-webkit-transform: translate(300px, 400px);
The "undo" effect that is not working:
-webkit-transform: translate(-300px, -400px);
I want to control the undo levels, so reseting the transforms is not an option.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您不能将同一变换函数的多个实例应用于一个元素。我认为第二个
-webkit-transform:translate();
语句取代了第一个语句,而不是补充它。-webkit-transform: translate(0, 0);
应该将元素返回到其原始(翻译前)位置。请参阅:I don’t think you can apply multiple instances of the same transform function to an element. I think the second
-webkit-transform:translate();
statement replaces the first, rather than acting in addition to it.-webkit-transform: translate(0, 0);
should return the element to its original (pre-translation) position. See:在应用转换之前,您可以保存
-webkit-transform
的当前值。撤消时只需恢复保存的值即可。Before applying transform you could save the current value of
-webkit-transform
. When undoing just restore the saved value.