1 Replies - 1492 Views - Last Post: 04 November 2008 - 02:54 AM

#1 srtech   User is offline

  • New D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 29-August 06

Javascript Text Rotator

Posted 27 May 2008 - 04:17 PM

Description: Drop the code in an HTML page and change the myquotes array to hold the text you want to rotate. See comments for more details.Rotates text on a page every few seconds. I use it to rotate a number of quotes from users. This snippet is quite basic, though it would be easy to dress it up with some Javascript effects, or other customizations.
<!-- create a element in your HTML like the following -->
<div id="quotetext" >
Text will go here. Be sure to add initial text here for users with Javascript disabled.
</div>


<!-- The easiest way is to place the below Javascript code after the above HTML. The better
     way would be to add in the <head> section of the document and call the rotatequote() function through the window.onload event. However this can cause problems if you have other scripts that use the 
     window onload settings -->
<script type="text/javascript" >
var myquotes = new Array(
	'Quote #1',
	'Quote #2',
	'Quote #3' // Leave the last quote without a comma at the end
	);

function rotatequote()
{
	thequote = myquotes.shift(); //Pull the top one
	myquotes.push(thequote); //And add it back to the end
	
	document.getElementById('quotetext').innerHTML = thequote;
	// This rotates the quote every 10 seconds.
	// Replace 10000 with (the number of seconds you want) * 1000
	t=setTimeout("rotatequote()",10000);
}

// Start the first rotation.
rotatequote();
</script>


Is This A Good Question/Topic? 0
  • +

Replies To: Javascript Text Rotator

#2 wennos   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 0
  • Joined: 04-November 08

Re: Javascript Text Rotator

Posted 04 November 2008 - 02:54 AM

This is a simple script and does the job well. I used HTML tags within the quotes and I can flexibly incorporate beautifully formated text and images! Thanks srtech!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1