循环遍历 Div
我需要使用 jQuery 循环浏览一些 div。我所说的循环是指我有一系列 7 个 div:
<div id="content-1">Sample text</div>
<div id="content-2">Sample text</div>
<div id="content-3">Sample text</div>
<div id="content-4">Sample text</div>
<div id="content-5">Sample text</div>
<div id="content-6">Sample text</div>
<div id="content-7">Sample text</div>
我需要发生的是每 5 秒我需要它们改变一次。因此,div“Content-1”将显示 5 秒,然后 div“Content 2”将显示 5 秒,依此类推。
我觉得这很容易做到,但当涉及到 JavaScript 和 jQuery 时,我是个白痴。
I need to cycle through some divs using jQuery. What I mean by cycle is that I have a series of 7 divs:
<div id="content-1">Sample text</div>
<div id="content-2">Sample text</div>
<div id="content-3">Sample text</div>
<div id="content-4">Sample text</div>
<div id="content-5">Sample text</div>
<div id="content-6">Sample text</div>
<div id="content-7">Sample text</div>
What I need to happen is every 5 seconds I need them to change. So the div "Content-1" would show for 5 seconds and then the div "Content 2" would show for 5 seconds etc.
I feel like this is easy to do but I'm an idiot when it comes to JavaScript and jQuery.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
演示: (延迟较短) http://jsfiddle.net/eFjnU/
如果您不想要淡入淡出动画,请使用
show
和hide
。您仍然需要给出一个持续时间,以便延迟
和回调能够正常工作。演示: (延迟较短) http://jsfiddle.net/eFjnU/1/
DEMO: (with a shorter delay) http://jsfiddle.net/eFjnU/
If you don't want the fade animation, use
show
andhide
. You still need to give a duration so that thedelay
and the callback will work.DEMO: (with a shorter delay) http://jsfiddle.net/eFjnU/1/
简单的 jQuery 淡入淡出画廊幻灯片,
悬停时暂停:
.fadeShow() jQuery 插件
如果您想将其转换为 simpls jQuery 插件 以允许不同的淡入淡出和暂停值并包含其他选项:
Simple jQuery fade gallery slideshow
with pause on hover:
.fadeShow() jQuery plugin
If you want to convert it to a simpls jQuery plugin in order to allow different fade and pause values and include other options:
我们需要迭代一个集合并处理它的可见性属性。
首先,让我向您展示我创建的两个库。第一个是 Iterable,它被设计用来处理各种迭代:
第二个是 Visiblary,它被设计用来处理各种可见性事件:
并且,假设一个使用这些工具并且已经创建了七个元素,这是解决问题的脚本:
We need to iterate a set and handle its visibility properties.
First of all, let me show you two libraries I have created. The first is
Iterable
, which is designed to handle all kinds of iterations:The second is
Visiblary
, which is designed to handle all kinds of visibility events:And, assuming that one uses these tools and the seven elements are already created, this is the script which solves the issue: