I'm trying to write a Jquery script that fades in Images as they are loaded, by using setInterval.
My current code is not working-- the "image-loading" class is not getting removed.
So two questions: 1) Why isn't the code working, and 2) is this the best way to accomplish what I want to do? Is there a better way?
(function($) {
var $props = $('#properties'),
$imgs = $props.find("img");
$imgs.addClass('image-loading');
(function updateImages() {
setTimeout(function() {
$imgs.each(function(){
$me = $(this);
// If image is loaded, remove class
$me.load(function(){
$me.removeClass('image-loading');
});
});
// if all images are loaded, stop the loop
$imgs.load(function () {
return false;
});
updateImages();
}, 100);
})();
})(jQuery);