...

View Full Version : Simple Rotation Script help needed please



nicky
08-26-2010, 09:56 PM
I'm in search for a simple and clean timed rotation script. I have these quotes, and right now they're coded so that a single quote displays and changes upon refresh. The script is really clean, and I would like to maintain the cleanliness but make the images rotate every couple of seconds. Here's the script...



<script type="text/javascript">
quote = new Array(3);
quote[0] = "Quote 1";
quote[1] = "Quote 2";
quote[2] = "Quote 3";
index = Math.floor(Math.random() * quote.length);
document.write(quote[index]);
</script>


It's probably a really simple piece of coding, but I'm still new to JavaScript, so it's obviously out of my range. I appreciate anyone who will help ;)

vwphillips
08-26-2010, 10:51 PM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title></title>
</head>

<body>

<span id="tst" ></span>
<script type="text/javascript">
/*<![CDATA[*/

function CngHTML(o){
this.obj=document.getElementById(o.ID);
this.quotes=o.quotes;
this.hold=o.Hold||5000;
this.cnt=0;
this.swap();
}

CngHTML.prototype.swap=function(){
this.obj.innerHTML=this.quotes[this.cnt];
this.cnt=++this.cnt%this.quotes.length;
var oop=this;
setTimeout(function(){ oop.swap(); },this.hold);
}

new CngHTML({
ID:'tst',
quotes:[
"Quote 1",
"Quote 2",
"Quote 3"
],
Hold:1200
});
/*]]>*/
</script>
</body>

</html>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum