...

View Full Version : Set a pause in Javascript



shanse3
08-02-2008, 01:09 AM
I have some javascript which scrolls through a bunch of images continuously. I'd like to make it so that it pauses on one image for 3 seconds, and then proceeds scrolling to the next one, where it pauses for 3 seconds, etc... I can't figure out how to accomplish this. Does anyone know how to do this?

Thanks!


/*
Cross browser Marquee II- Dynamic Drive (www.dynamicdrive.com)
For full source code, 100's more DHTML scripts, and TOS, visit http://www.dynamicdrive.com
Credit MUST stay intact
*/

//Specify the marquee's width (in pixels)
var marqueewidth="190px"
//Specify the marquee's height
var marqueeheight="150px"
//Specify the marquee's marquee speed (larger is faster 1-10)
var marqueespeed=-20
//Pause marquee onMousever (0=no. 1=yes)?
var pauseit=1


//Specify the marquee's content
//Keep all content on ONE line, and backslash any single quotations (ie: that\'s great):
var scrolling = new Array();
scrolling[0] ='<p><img src="/images2/quotes/gbc.jpg" border="0" ></p>'
scrolling[1] ='<p><img src="/images2/quotes/casagrande.jpg" border="0" ></p>'
scrolling[2] ='<p><img src="/images2/quotes/energy.jpg" border="0" ></p>'
scrolling[3] ='<p><img src="/images2/quotes/northwest.jpg" border="0" ></p>'
scrolling[4] ='<p><img src="/images2/quotes/stannah.jpg" border="0" ></p>'
scrolling[5] ='<p><img src="/images2/quotes/venice.jpg" border="0" ></p>'
scrolling[6] ='<p><img src="/images2/quotes/farner.jpg" border="0" ></p>'
scrolling[7] ='<p><img src="/images2/quotes/gardner.jpg" border="0" ></p>'
scrolling[8] ='<p><img src="/images2/quotes/haley.jpg" border="0" ></p>'
scrolling[9] ='<p><img src="/images2/quotes/hayes.jpg" border="0" ></p>'
scrolling[10] ='<p><img src="/images2/quotes/imi.jpg" border="0" ></p>'
scrolling[11] ='<p><img src="/images2/quotes/midland.jpg" border="0" ></p>'
scrolling[12] ='<p><img src="/images2/quotes/prettl.jpg" border="0" ></p>'





////NO NEED TO EDIT BELOW THIS LINE////////////

marqueespeed=(document.all)? marqueespeed : Math.max(1, marqueespeed-10) //slow speed down by 1 for NS
var copyspeed=marqueespeed
var pausespeed=(pauseit==0)? copyspeed: 0
var iedom=document.all||document.getElementById
var actualheight=''
var cross_marquee, ns_marquee
function getstartpos(istr,iend){
var seed = Math.random(); //0-1
seed = Math.round(seed*iend);
return seed;

}
function getImages(){
var len = scrolling.length;
var start = getstartpos(0,len);
var newstr = '';
for( var i=start;i<len; i++)
newstr += scrolling[i];
for( var i=0;i<start; i++)
newstr += scrolling[i];

return newstr;
}
function getmarqueecontent(){
var marqueecontent='<font face="Verdana, helvetica, sans-serif" size="1">'
+ getImages()
+'</font>'
return marqueecontent;
}
function populate(){
if (iedom){
cross_marquee=document.getElementById? document.getElementById("iemarquee") : document.all.iemarquee
cross_marquee.style.top=parseInt(marqueeheight)+8+"px"
cross_marquee.innerHTML=getmarqueecontent();
actualheight=cross_marquee.offsetHeight
}
else if (document.layers){
ns_marquee=document.ns_marquee.document.ns_marquee2
ns_marquee.top=parseInt(marqueeheight)+8
ns_marquee.document.write(marqueecontent)
ns_marquee.document.close()
actualheight=ns_marquee.document.height
}
lefttime=setInterval("scrollmarquee()",20)
}
window.onload=populate


function scrollmarquee(){

if (iedom){
if (parseInt(cross_marquee.style.top)>(actualheight*(-1)+8))
cross_marquee.style.top=parseInt(cross_marquee.style.top)-copyspeed+"px"
else
cross_marquee.style.top=parseInt(marqueeheight)+8+"px"
}
else if (document.layers){
if (ns_marquee.top>(actualheight*(-1)+8))
ns_marquee.top-=copyspeed
else
ns_marquee.top=parseInt(marqueeheight)+8
}
}

if (iedom||document.layers){
with (document){
if (iedom){
write('<div style="position:absolute;width:'+marqueewidth+';height:'+marqueeheight+';top:150px;right:5px;overflow:hidde n" onMouseover="copyspeed=pausespeed" onMouseout="copyspeed=marqueespeed">')
write('<div id="iemarquee" style="position:absolute;left:0px;top:0px;width:100%;">')
write('</div></div>')
}
else if (document.layers){
write('<ilayer width='+marqueewidth+' height='+marqueeheight+' name="ns_marquee">')
write('<layer name="ns_marquee2" width='+marqueewidth+' height='+marqueeheight+' left=0 top=0 onMouseover="copyspeed=pausespeed" onMouseout="copyspeed=marqueespeed"></layer>')
write('</ilayer>')
}
}
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum