Given a list of images, how do I get them to appear in order in JavaScript / HTML? -


i building flask app webpage receives list of images (and metadata) in particular order display in grid structure, similar how clothing website shows images of clothing. problem that, currently, images appearing in order of fastest loading and, hence, different order of images each time reload page.

the get_similar_images function receive list of images , function populateimages append image , metadata html.

essentially, not want for loop in get_similar_images move onto next iteration until previous image loaded. appreciate on how implement this!

function populateimages(imageurl, retailer, name, price, retailerurl) {     var block = document.createelement("div");     block.classname = 'image-block';      var img = document.createelement("img");     img.src = imageurl;     img.classname = 'clickable-image';      // link external site     var clickablelink = document.createelement("a");     clickablelink.href = retailerurl;     clickablelink.target = "_blank";     clickablelink.appendchild(img);      // add metadata             var description = document.createelement("div");      var retailername = document.createelement("p");     retailername.classname = 'description-text';     var retailernametext = document.createtextnode(retailer);     retailername.appendchild(retailernametext);     description.appendchild(retailername);      var productname = document.createelement("p");     productname.classname = 'description-text';     var productnametext = document.createtextnode(name);     productname.appendchild(productnametext);     description.appendchild(productname);      var productprice = document.createelement("p");     productprice.classname = 'description-text';     var productpricetext = document.createtextnode('$'+price);     productprice.appendchild(productpricetext);     description.appendchild(productprice);      // resize image     var actualh;     var actualw;     var newh;     var neww;     img.onload = function() {         actualw = this.width;         actualh = this.height;         var newsize = scalesize(300, 300, actualw, actualh);         this.width = newsize[0];         this.height = newsize[1];         block.appendchild(clickablelink);         block.appendchild(description);         document.getelementbyid('imagediv').appendchild(block);     };  }  function get_similar_images(image_name) {     $.ajax({         type: "post",         contenttype: "application/json; charset=utf-8",         url: "/get_similar",         datatype: "json",         async: true,         data: json.stringify({name: image_name}),         success: function(data) {             var image_list = data.images;             var category = data.category;             var retailers = data.retailers;             var names = data.names;             var prices = data.prices;             var urls = data.urls;             (var i=0; i<image_list.length; i++) {                 var url = "static/products/"+category+"/"+image_list[i];                 populateimages(url, retailers[i], names[i], prices[i],                      urls[i])             }         },         error: function(xhr, status, error) {         }     }); } 


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -