/    Sign up×
Community /Pin to ProfileBookmark

How to Rotate/Slideshow Text DIVs on page?

I am trying to modify the script below to slideshow/rotate through a handful of text DIVs.

I need these DIVs to appear in order– div 1, then div 2, then div 3. Each would appear for 5 seconds, then show the next div… but in order.

The script below works well for Random divs, but I need them to be in order– div 1, div 2, div 3… each time.

[CODE]

<div id=”d1″ style=”display:none;”>some text 1</div>
<div id=”d2″ style=”display:none;”>some text 2</div>
<div id=”d3″ style=”display:none;”>some text 3</div>

<script type=”text/javascript”>
divs = [‘d1′,’d2′,’d3’];

function hideDivs() {
for (var i=0; i<divs.length; i++)
document.getElementById(divs[i]).style.display = ‘none’;
}

function showDiv() {
hideDivs(); //hide them all before we show the next one.
var randomDiv = divs[Math.floor(Math.random()*divs.length)];
var div = document.getElementById(randomDiv).style.display =
‘block’;

setTimeout(showDiv,500); //set a delay before showing the next div
}

showDiv();
</script> [/CODE]

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@s-p-nFeb 28.2013 — try not getting a random div and getting the next div until there are none, then get the first again.

http://jsfiddle.net/K6dzD/
Copy linkTweet thisAlerts:
@ooooauthorFeb 28.2013 — try not getting a random div and getting the next div until there are none, then get the first again.
[/QUOTE]


Hmm. Would I just do something like this:

[CODE]function showDiv() {
hideDivs(); //hide them all before we show the next one.
var randomDiv = divs[1,2,3)];
var div = document.getElementById(randomDiv).style.display =
'block';[/CODE]
Copy linkTweet thisAlerts:
@s-p-nFeb 28.2013 — 'divs[1,2,3)];' that is not javascript, and I can't tell what you meant to put instead. Did you look at the code in the jsfiddle?
Copy linkTweet thisAlerts:
@ooooauthorFeb 28.2013 — I couldn't figure out how to do this in all the JavaScript resources I looked for.

1,2,3 was my last futile attempt. I guess neither of us can figure this one out.
Copy linkTweet thisAlerts:
@ooooauthorFeb 28.2013 — I'm trying to rotate out 3 text-based DIV tags, one after the other.

Div 1 should appear for 5 seconds...

Then Div 2 should appear for 5 seconds...

Then Div 3 should appear for 5 seconds...

The script I posted rotates out these DIV tags randomly. The script works, but I need to tweak it so it does what I need.

I need the script to show div 1, div 2, div 3-- in that order, not randomly.

I can't figure out how to do that.
Copy linkTweet thisAlerts:
@s-p-nFeb 28.2013 — Did you see the link I gave you?? Here's another: http://jsfiddle.net/K6dzD/embedded/result/

I'll post it again, since it appears you missed the first time. This is the solution to your problem:

http://jsfiddle.net/K6dzD/light/
Copy linkTweet thisAlerts:
@ooooauthorFeb 28.2013 — Did you see the link I gave you?? Here's another: http://jsfiddle.net/K6dzD/embedded/result/

I'll post it again, since it appears you missed the first time. This is the solution to your problem:

http://jsfiddle.net/K6dzD/light/[/QUOTE]



Thanks. I actually can't get this script to work on my site. It appears blank when I embed it in the homepage. It works in JSFiddle. But, I need to have each DIV ID tag a separate DIV. My CSS stylesheet gives each DIV an h2 title with a div id="headline". Each DIV tag has formatted text, a few images, an h2 heading, and some text. I can't seem to add rich text to the script you posted.

I can't imagine what I'm doing wrong here, and have nearly through the PC out the window more than a few times. I've probably just been staring at the page so long that I'm missing something obvious and that's why it's not working. ?
×

Success!

Help @oooo spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...