css 过渡_没有_悬停?

发布于 2024-11-25 02:10:52 字数 471 浏览 0 评论 0原文

足够简单的问题:

当通过伪选择器(即 :hover:active 等)触发动画不合适/不可行时,是否可以利用 css 转换?

我的用例是我想要在提交表单后制作一些动画。我想我可以做类似的事情:

.success_message { ...transition stuff + opacity: 0 }
.success_message.shown { opacity: 1 }

然后使用 javascript,我将 shown 类添加到我想要动画的这个元素中。

为什么不直接使用 jQuery 或类似的 animate?我很高兴你问了。 CSS 转换在 iPhone 和其他移动设备(我的目标平台)上要流畅得多。目前我正在使用 jQuery 制作动画,但它们并不那么流畅。


编辑以澄清我对伪选择器的询问。

Simple enough question:

Is it possible to leverage css transitions when it would would not be appropriate/feasible to trigger animations via pseudo selectors (ie :hover, :active, etc)?

My use case is I want something to animate after form submission. I was thinking I would be able to do something like:

.success_message { ...transition stuff + opacity: 0 }
.success_message.shown { opacity: 1 }

Then using javascript, I would add the shown class to this element I want to animate.

Why not just use jQuery or similar to animate? I'm glad you asked. The CSS Transitions are much smoother on the iPhone and other mobile devices, which are the platforms I'm targeting. Currently I'm doing animations with jQuery, but they're just not as smooth as they could be.


Edited to clarify what I was asking about pseudo-selectors.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

飞烟轻若梦 2024-12-02 02:10:52

一切都应该按您的预期进行。 JSFiddle: http://jsfiddle.net/ghayes/zV9sc/12/

 .success_message {
   opacity: 0.0;
   transition: opacity 0.3s linear;
   -webkit-transition: opacity 0.3s linear;
   -moz-transition: opacity 0.3s linear;  
   -o-transition: opacity 0.3s linear;
 }

 .success_message.shown {
   opacity: 1.0;
 }

如果没有解决您的问题,请包含更多代码示例或浏览器详细信息。祝你好运!

Everything should work as you expect. JSFiddle: http://jsfiddle.net/ghayes/zV9sc/12/

 .success_message {
   opacity: 0.0;
   transition: opacity 0.3s linear;
   -webkit-transition: opacity 0.3s linear;
   -moz-transition: opacity 0.3s linear;  
   -o-transition: opacity 0.3s linear;
 }

 .success_message.shown {
   opacity: 1.0;
 }

If this does not solve your issue, please include further code samples or browser specifics. Good luck!

听,心雨的声音 2024-12-02 02:10:52

是的,你可以这样做。每当 css 属性发生变化时,CSS 转换都会起作用,即使是因为类发生了变化。

Yes, you can do that. Css transitions work any time a css property changes, even if it was because the class changed.

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