jQuery recursive image loading and IE -


i'm trying load bunch of images recursively , works in browsers except god-forsaken ie because of restriction of 13 recursions.

now can fix on own, want follow "best practice", speak, since i'm still learning jquery. , i'm guessing gurus around here give helpful pointer. how suggest fixing it?

my code snippet:

 $(document).ready(function(){     loadthumbs(["1.jpg","2.jpg","3.jpg","4.jpg","5.jpg","6.jpg","7.jpg","8.jpg",                "9.jpg","10.jpg","11.jpg","12.jpg","13.jpg","14.jpg","15.jpg",                "16.jpg","17.jpg","18.jpg","19.jpg","20.jpg"], 0); }); function loadthumbs(files, index){     if(index == files.length) return;     var file = files[index];     var image = new image();     $(image)         .load(function(){             $("#container").append(image);             loadthumbs(files, index+1);         })         .addclass("thumb")         .attr("src", file); }

if try in ie (8 in case) you'll stack overflow error.

thanks!

i assume you're loading images one-by-one because looks prettier, loading them in parallel. little rewrite should solve stack overflow problem:

before: loadthumbs(files, index+1);  after: var nextindex = index + 1; settimeout(function() { loadthumbs(files, nextindex) }, 0) 

and yes, add check array boundary @ top of function: if (!files[index]) return;, bet that's reason why code breaks in ie8.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -