Results 1 to 3 of 3

Thread: have code - trying to avoid 30 sec delay from start

  1. #1
    Join Date
    Jul 2008
    Posts
    138
    Thanks
    13
    Thanked 1 Time in 1 Post

    Default have code - trying to avoid 30 sec delay from start

    I am using the following javascript in a site because the testimonials must continue to rotate on a 30 second basis.

    Code:
    <script language="JavaScript">
    var seconds=30; /* rotate every 30 seconds */
    function rotate()
    {
            var Quotation=new Array()
    
            // QUOTATIONS
            Quotation[0] = '';
            Quotation[1] = '';
            so on..
    
            var which = Math.round(Math.random()*(Quotation.length - 1));         
    document.getElementById('textrotator').innerHTML = Quotation[which];
    }
    function start()
    {
      setInterval("rotate()",seconds*1000);
    }
    </script> 
    <div id="textrotator"><!--Quotations will be displayed here--></div>
    <script>
    window.onload=start;
    </script>
    The above works just fine, but the issue is that it takes 30 seconds for the first testimonial to appear. This is being used dynamically in the header of the site so for that first 30 secs it looks a little blank.

    I know more about php than javascript, so someone might know a nifty work around to solve that because the code serves it's purpose other than that.

    Thank you for any suggestions.

  2. #2
    Join Date
    Feb 2008
    Location
    Cebu City Philippines
    Posts
    1,160
    Thanks
    17
    Thanked 277 Times in 275 Posts

    Default

    Hope this helps:
    Code:
    <script language="JavaScript">
    var seconds=30; /* rotate every 30 seconds */
    function rotate()
    {
            var Quotation=new Array()
    
            // QUOTATIONS
            Quotation[0] = 'Content1';
            Quotation[1] = 'Content2';
            var which = Math.round(Math.random()*(Quotation.length - 1));         
    document.getElementById('textrotator').innerHTML = Quotation[which];
    setTimeout('rotate()',seconds*1000);
    }
    </script> 
    <div id="textrotator"><!--Quotations will be displayed here--></div>
    <script>
    window.onload=rotate;
    </script>
    Learn how to code at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph!

  3. The Following User Says Thank You to rangana For This Useful Post:

    ?foru (09-06-2008)

  4. #3
    Join Date
    Jul 2008
    Posts
    138
    Thanks
    13
    Thanked 1 Time in 1 Post

    Default

    That's perfect rangana! This is now seamless from page to page. Thank you

Bookmarks

Posting Permissions

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