[英]How to fade in text without using setInterval? Is there a CSS way to do this?
I want to make some text fade in. I've done such things using Javascript and setInterval. 我想让一些文字淡入。我已经使用Javascript和setInterval完成了这些事情。 That works but it seems like too much gunk for such a simple effect.
这有效,但对于这样一个简单的效果来说似乎太多了。
Is there a CSS way to do a text fade in? 是否有CSS方式来淡入文本? For instance, it starts as 0% opacity and becomes 100% opaque over a time frame that I specify.
例如,它以0%不透明度开始,并在我指定的时间范围内变为100%不透明。
Thanks. 谢谢。
You can do it on :hover
with CSS3 transformations. 你可以这样做
:hover
使用CSS3转换进行:hover
。 A very simple example: http://jsfiddle.net/xaBgQ/ 一个非常简单的例子: http : //jsfiddle.net/xaBgQ/
不仅仅是CSS(在所有浏览器中),jQuery为这样的效果提供了一个很好的API, fadeIn方法可能是一个很好的选择。
CSS3过渡支持这一点,但支持目前有点不稳定。
Yes, your can user the CSS3 transition timing functions. 是的,您可以使用CSS3转换计时功能。
Have a look here for some examples: 看看这里的一些例子:
http://www.the-art-of-web.com/css/timing-function/ http://www.the-art-of-web.com/css/timing-function/
Some ideas that come to mind: 想到的一些想法:
1) An animation framework like jQuery, YUI, etc. Sure, those probably use setInterval internally but then it's their gunk and not yours. 1)像jQuery,YUI等动画框架。当然,那些可能在内部使用setInterval但是它们是他们的gunk而不是你的。
2) CSS3 - If you only need to work on the latest browsers or have a fall back plan, this might be a good way to go. 2)CSS3 - 如果您只需要使用最新的浏览器或有后备计划,这可能是一个很好的方法。 Plenty of examples if you Google for "CSS3 animation"
很多例子,如果你谷歌为“CSS3动画”
3) If your text is static and small, perhaps an animated GIF instead. 3)如果你的文字是静态的和小的,也许是一个动画GIF。
Hope this helps! 希望这可以帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.