简体   繁体   English

如何在不使用setInterval的情况下淡入文本? 有没有CSS方法来做到这一点?

[英]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.

相关问题 在不使用“on”或“setInterval”或“setTimeout”的情况下,如何更改动态生成的元素的文本 - Without using 'on' or 'setInterval' or 'setTimeout' , how do I change the text of an element that is dynamically generated 如何使用setInterval和CSS样式更改文本动画? - How to change text animation using setInterval and styling by CSS? HTML / CSS / JS - 如何使用setInterval更改文本? - HTML/CSS/JS - How can I change text using a setInterval? MaterialUI 文本使用 useEffect 和 setInterval 淡出 - MaterialUI text fade with useEffect and setInterval 我如何获得淡入淡出的动画<li>使用 React 还是 CSS? - how do I get a fade in animation for <li> using React or CSS? 使用 css 和 setInterval 向下移动文本 - move the text downwards using css and setInterval 有没有一种方法可以在不使用 setInterval 的情况下动态绑定字符串及其输出的文本? - Is there a way I can dynamically bind a string and the text it outputs without using setInterval? 如何使用jQuery向文本幻灯片添加淡入和淡出效果 - How do add a Fade in and Fade out effect to a text slide using jquery setInterval淡入,然后淡出纯JavaScript no jQuery或CSS - setInterval to fade in then fade out pure javascript no jquery or css 如何使用 JavaScript 和 CSS 进行淡入和淡出 - How to do fade-in and fade-out with JavaScript and CSS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM