I have an array with the URLs of images that I add to the page as tags img. I add them to hidden ones and disappear when they load. This works, but I would like to add a little delay between each of them so that it does not fade so much at the same time.
function ajaxCallback(data)
{
if(data && data.images)
for(var n in data.images)
{
var image = $('<img>')
.prop(data.images[n])
.css({opacity: 0})
.appendTo('#output')
.load(imageLoaded);
}
}
function imageLoaded()
{
$(this)
.animate({opacity: 1});
}
At the moment, if they load quickly enough, they will all gradually disappear. I would like to delay a little between them. Tried to add a challenge delay, but that didn't seem to do much. I think I may have to do something with the queue or something else, but I can’t figure out how to do it.
What is the best way to do this?
Svish source
share