PDA

View Full Version : have code - trying to avoid 30 sec delay from start



?foru
09-06-2008, 02:15 AM
I am using the following javascript in a site because the testimonials must continue to rotate on a 30 second basis.


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

rangana
09-06-2008, 02:52 AM
Hope this helps:


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

?foru
09-06-2008, 03:04 AM
That's perfect rangana! This is now seamless from page to page. Thank you