I am writing script for lightbox gallery. I want to user prelaod techique for elegant image loading. My current script is:
for (var i in imgs) {
var tmp_thumb=$('img');
tmp_thumb.on('load', function(){
O.SG.thumbs.append('<li><a style="background-image:url(\'' + imgs[i].thumb + '\')"></a></li>');
$(this.)remove();
}).attr('src', imgs[i].thumb);
}
The problem is, when load
callback is called, loop counter i
has almost always the last value from img
array.
How to pass to callback the proper value of i
from the context of lode