css 过渡_没有_悬停?
足够简单的问题:
当通过伪选择器(即 :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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一切都应该按您的预期进行。 JSFiddle: http://jsfiddle.net/ghayes/zV9sc/12/
如果没有解决您的问题,请包含更多代码示例或浏览器详细信息。祝你好运!
Everything should work as you expect. JSFiddle: http://jsfiddle.net/ghayes/zV9sc/12/
If this does not solve your issue, please include further code samples or browser specifics. Good luck!
是的,你可以这样做。每当 css 属性发生变化时,CSS 转换都会起作用,即使是因为类发生了变化。
Yes, you can do that. Css transitions work any time a css property changes, even if it was because the class changed.