Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    May 2008
    Location
    Michigan
    Posts
    216
    Thanks
    10
    Thanked 1 Time in 1 Post

    Simple Rotation Script help needed please

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

    Code:
    <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

  • #2
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,519
    Thanks
    3
    Thanked 507 Times in 494 Posts
    Code:
    <!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>
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •