i trying create function stop looking next slide , not give me error message asset not found.
i have 6 assets in folder.
avoiding error:
get file:///users/ferfas/desktop/1.33_1024x768/initialframes/frame_7.jpg net::err_file_not_found
code:
var pictureindex = 1; var baseurl = "initialframes/"; var image_url = undefined; var timer = setinterval(next, 2500); var newimage = new image(); newimage.onload = imagefound; newimage.onerror = imagenotfound; function next() { image_url = baseurl + 'frame_' + pictureindex + '.jpg'; tryloadimage(image_url); } function tryloadimage(url) { newimage.src=url; } function imagefound() { document.getelementbyid("backinit").src = image_url; pictureindex++; } function imagenotfound() { // perform function stop calling next() clearinterval(timer); }
why use setinterval @ all?
you can load images iteratively:
var pictureindex = 1; var baseurl = "initialframes/"; var image_url = undefined; var newimage = new image(); newimage.onload = imagefound; newimage.onerror = imagenotfound; function next() { image_url = baseurl + 'frame_' + pictureindex + '.jpg'; tryloadimage(image_url); } function tryloadimage(url) { newimage.src=url; } function imagefound() { document.getelementbyid("backinit").src = image_url; pictureindex++; //you can check here if pictureindex image exists, , call next if exists // if (imageexists()) { next(); // } } function imagenotfound() { console.log('done loading images...'); } next();
Comments
Post a Comment