javascript - Continuing for loop only when image loads -
function readxml(){ var xmldoc = loadxml(); var x = xmldoc.getelementsbytagname("image"); (i = 0; < x.length; i++) { if (i == 600){ break; } var path = x[i].getelementsbytagname("path")[0].childnodes[0].nodevalue; var title = x[i].getattribute("class"); this.imagearray.push(new infoimage(path,title)); while(this.imagearray[i].isimageloaded() == false); //something console.log(this.imagearray[i].getmaxpixels()); } } function infoimage(path,title){ this.path = path; this.title = title; this.color = undefined; this.maxpixels = undefined; this.imageloaded = false; this.init = function(){ var canvas = document.queryselector("canvas"); var img_color = new image_processing_color(canvas); var img = new image(); var info_image = this; img.onload = function () { img_color.init(img); info_image.color = img_color.getdominantcolor(); info_image.maxpixels = img_color.getdominantcolorpixels(); info_image.imageloaded = true; }; img.src = path; }; this.isimageloaded = function(){ return this.imageloaded; } this.getpath = function(){ return this.path; }; this.gettitle = function(){ return this.title; }; this.getcolor = function(){ return this.color; }; this.getmaxpixels = function(){ return this.maxpixels; }; this.init(); }
i want for
loop continue next iteration when img.onload completes. while
i'm using blocks code , doesn't let img.onload complete. there way this? without changing code structure.
you can check .complete property of img:
var x = document.getelementbyid("myimg").complete; result can true or false
Comments
Post a Comment