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.
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/
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:
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: