Go Back   Dynamic Drive Forums > General Coding > JavaScript
Search Dynamic Drive Forums:

Reply
 
Thread Tools Search this Thread
  #1  
Old 09-06-2008, 03:15 AM
?foru ?foru is offline
Regular Coders
 
Join Date: Jul 2008
Posts: 102
Thanks: 8
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.
Reply With Quote
  #2  
Old 09-06-2008, 03:52 AM
rangana's Avatar
rangana rangana is offline
Elite Coders
 
Join Date: Feb 2008
Location: Cebu City Philippines
Posts: 1,115
Thanks: 17
Thanked 267 Times in 265 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>
Reply With Quote
The Following User Says Thank You to rangana For This Useful Post:
?foru (09-06-2008)
  #3  
Old 09-06-2008, 04:04 AM
?foru ?foru is offline
Regular Coders
 
Join Date: Jul 2008
Posts: 102
Thanks: 8
Thanked 1 Time in 1 Post
Default

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

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 09:32 PM.

Home - Contact Us - Archives - Link to DD - Top 

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.