javascript - Loop through a set of names, taking action at interval -
in html page using javascript/jquery, have array of image file names (arlistx). on page, have routine called show(pict) processes image in ways, displays it.
i want simulate slideshow running each image through show(pict) @ specific interval.
the best luck i've had far getting final image show (evidently, images run through code last shows).
using interpretation of 5226285 (settimeout-in-a-for-loop-and-pass-i-as-value), came this:
function dosettimeout(i) { settimeout(function() { show(arlistx[i]); }, 5000); } . . . //[main] for(i=0; i<arlistx.length; i++) { dosettimeout(i); } . . . function show(pict) { $("#ourpicture").attr('src',pict); . . . }
i'm doing wrong , appreciate suggestion.
you need incrementally set timeout i*5000
display @ 0, 5000, 10000, 15000, etc. wrote calls them after 5 seconds.
function dosettimeout(i) { settimeout(function() { show(arlistx[i]); }, i*5000); } . . . //[main] for(i=0; i<arlistx.length; i++) { dosettimeout(i); } . . . function show(pict) { $("#ourpicture").attr('src',pict); . . . }
Comments
Post a Comment