Fade in Multiple Divs When Each is Loaded
I'm trying to have multiple divs fade in when the content of each is done loading. Can't seem to get it to work.
$(function() {
$(".postphoto").bind("load", function () { $(this).fadeIn(); });
});
There are multiple divs with the same class, and I need to fade each in when they are r开发者_JAVA技巧eady. Any ideas of where I'm going wrong?
Thanks ahead of time!
You could look at using the imagesLoaded plugin to check if each image has loaded and then fade it in when successful.
The plugin also has the benefit of allowing for cached images.
From jQuery docs. Emphasis, mine.
The load event is sent to an element when it and all sub-elements have been completely loaded. This event can be sent to any element associated with a URL: images, scripts, frames, iframes, and the window object.
So unless it's one of those elements described above, there's not a good way to tell when data for a specific div has loaded, the document.ready fires when the DOM has finished loading, excluding images.
精彩评论