CSS3 变换:如何撤消变换操作?

发布于 2024-12-18 23:48:33 字数 351 浏览 4 评论 0原文

我想对

应用翻译转换,然后能够将该
返回到其原始位置。

对负值应用相同的操作不会将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

℡寂寞咖啡 2024-12-25 23:48:33

我认为您不能将同一变换函数的多个实例应用于一个元素。我认为第二个 -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:

挖个坑埋了你 2024-12-25 23:48:33

在应用转换之前,您可以保存 -webkit-transform 的当前值。撤消时只需恢复保存的值即可。

Before applying transform you could save the current value of -webkit-transform. When undoing just restore the saved value.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文