动态单词交换动画
我正在尝试为页面上的文本创建一个动画,每隔几秒钟,就会用列表中的另一个单词更改一个单词。示例:我有一个标题,上面写着“这很酷”,但我希望每隔几秒将“酷”替换为“neat/awesome/groovy/etc”。
老实说,我不确定解决这个问题的最佳方法(就使用什么技术而言),而且我找不到适用于现代浏览器的代码简介。非常感谢帮助!
I'm trying to create an animation for text on a page that, every few seconds, changes one word out with another word from a list. Example: I have a header that says, "This is cool," but I want "cool" to be replaced every few seconds by "neat/awesome/groovy/etc".
I'm honestly not sure the best way to go about this (in terms of what technology to use) and I can't find a blurb of code that works with modern browsers. Help is greatly appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在纯JS
http://jsfiddle.net/M5gxH/3/
in Pure JS
http://jsfiddle.net/M5gxH/3/
在 jQuery 中,我会做这样的事情:
http://jsfiddle.net/6SRaB/1/
关键是使用带有 ID 的 SPAN 标签,您可以快速挑选出来。
In jQuery, I'd do something like this:
http://jsfiddle.net/6SRaB/1/
The key is to use a SPAN tag with an ID that you can pick out quickly.
这个问题很老了,但它出现在我的谷歌搜索中。在 2018 年,您可以使用 CSS 动画轻松实现此行为,而无需任何额外的 JavaScript 代码。
以下内容应该可以满足您的需求:
请注意,这只是一个垂直滑动的示例。 CSS 在动画/过渡方面基本上有无限的可能性。
This question is quite old but it showed up in a google search for me. In 2018 you can easily implement this behavior with CSS Animations without the need for any additional JavaScript code.
The following should give you what you need:
Note that this is just an example with vertical sliding. There are basically endless possibilities with CSS in terms of animations/transitions.