Note that there are some explanatory texts on larger screens.

plurals
  1. POJquery each() goes faster as load()
    primarykey
    data
    text
    <p>I have something like this</p> <pre><code>function loadImages(){ var num = 1; $('.myElement').each(function(){ var image = $("&lt;img&gt;").attr("src",mySrc).load(function(){ if(num == 1){ //do something - does not work } }); num++; }); } </code></pre> <p>And condition if(num == 1) does not work at all. I think, it's because while first image will be loaded, each() function still works and var num has some greater value, as my condition inside load() function goes to play... how can I fix it?</p> <p>thx</p> <p>full function code</p> <pre><code>function loadThumbs(imageCount){ var perc = 0; var cache = []; var thumbHolderWidth = 0; var thumbHolderHeight = 0; $('#thumbs').find(".image_thumb").each(function(enumThumb){ if(enumThumb == 0){ $(this).addClass('active'); } var thisThumbSrc = $(this).find('img').attr('src'); var smallim = $("&lt;img&gt;").attr("src",thisThumbSrc).load(function(){ var thumbWidth = this.width; var thumbHeight = this.height; thumbHolderWidth = thumbHolderWidth + thumbWidth + 12; if(thumbHeight &gt; thumbHolderHeight){ thumbHolderHeight = thumbHeight; } }); cache.push(smallim); var imgSrc = $(this).attr('bigimg'); var im = $("&lt;img&gt;").attr("src",imgSrc).load(function(){ if(enumThumb == 0){ imWidth = this.width; imHeight = this.height; resizeOverlay(imWidth,imHeight,imgSrc); } perc = perc + (100/imageCount); var loaderWidth = Math.round(winWidth*perc/100); $('#thumb_loader').stop().animate({'width':loaderWidth+'px'}); if(Math.round(perc) &gt;= 100){ $('#thumb_loader').animate({ 'height':'1px', 'margin-top':'0px' },'fast',function(){ $('#thumb_loader').addClass('loaded'); }); } }); cache.push(im); }); $('#images_overlay').find('#thumbs').css({ 'width':thumbHolderWidth+'px', 'height':thumbHolderHeight+10+'px', 'left':winWidth/2-thumbHolderWidth/2+'px' }) $('#images_overlay').find('#thumbs').fadeIn(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload