开发者

Is there a reason why ('img').load doesn't work (jQuery)?

I have a set of images tha开发者_如何学JAVAt I wanted to load first before executing the next line of code. The code is like:

$('div.some_class img').load(function() {
    // do something to div.some_class img
});

However, the images do not load before executing the commands. When I try (window).load though, it works.

My question is, why doesn't ('div.some_class img').load work? Or is it because I'm using a class selector which is the slowest way to select an element?


from http://api.jquery.com/load-event/

Caveats of the load event when used with images

A common challenge developers attempt to solve using the .load() shortcut is to execute a function when an image (or collection of images) have completely loaded. There are several known caveats with this that should be noted. These are:

  • It doesn't work consistently nor reliably cross-browser
  • It doesn't fire correctly in WebKit if the image src is set to the same src as before
  • It doesn't correctly bubble up the DOM tree
  • Can cease to firefor images that already live in the browser's cache

Hope this answers your question.


https://gist.github.com/268257 - this is a jQuery plugin to check for all images loaded

I don't think that load checks for the image to have actually loaded as much as that the tag has loaded? I had the same problem so used the above plugin

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜