javascript - jQuery each() and load() ordering -


i have script loops through series of json objects represent images, loop loads image , once has been loaded appends element on website/application.

the images in correct order in json appearing in different orders depending on images load quickest because appended first. want make sure whatever order images load, always in correct order (the order loop denotes).

the method i'm hoping end allow me access style of wrapping anchor before image loaded show loading icon also.

here's part of script talking about:

$.each(project.images, function (index, image){  var image_src = '<?= image_path ?>library/preview/'+ image.file_name; var image_markup = $('<img class="new-image" />').attr('src', image_src)                                                      .load(function(){      if (this.complete)      {          var anchor_markup = $('<a href="javascript:void(0)" class="image-anchor" data-image-index="'+ index +'" id="image-index-'+ index +'">');         $(anchor_markup).append(image_markup);         globals.markup.image_slider.append(anchor_markup);         $('.new-image').fadein(200).removeclass("new-image");     } }); }); 

the example can seen @ http://www.staging.codebycoady.com/work

if want them in correct order append them without waiting them load, hide them , in onload callback toggle them visible.


Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -