jQuery的替代绑定('LOAD')与图像的使用绑定、图像、jQuery、LOAD

由网友(細嫩苌腿歐巴)分享简介:可能重复: jQuery回调的图像加载(即使当图像被缓存) 因此​​, .load()方法已pcated jQuery中去$ P $。 负载()是'绑定('负荷',功能)的快捷方式。So the .load() method has been deprecated in jQuery. load() is a s...

可能重复:   jQuery回调的图像加载(即使当图像被缓存)

因此​​, .load()方法已pcated jQuery中去$ P $。 负载()是'绑定('负荷',功能)的快捷方式。

So the .load() method has been deprecated in jQuery. load() is a shortcut for `bind('load', function).

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

Load事件与图像使用时注意事项

有一个共同的挑战,开发人员尝试使用.load来解决()   快捷键是执行的函数,当图像(或集合   图像)已经完全加载。有几种公知的警告与   这一点,应该注意。它们是:

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:

这并不一致,也没有可靠的跨浏览器的工作,它不   WebKit中正确地触发如果图像的src被设置为相同的src作为   它没有正确的泡沫之前,DOM树停止火   对于已经生活在浏览器的cache`图片

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 fire for images that already live in the browser's cache`

一个人如何进行图像负荷持续函数?我目前的code看起来像这样:

How does one perform a function on image load consistently? My Current code looks like so:

$(newImage).bind('load', function() {
    createSlices(slide); 
});

之后,但是阅读文档(虽然我还没有发现任何问题),我很担心它可能不会触发了一些用户。

However after reading the docs (although I haven't noticed any problems) I am worried it may not fire for some users.

推荐答案

试试这个插件的男人:一个名为 waitforimages 插件:的 https://github.com/alexanderdickson/waitForImages (向下滚动,你会看到各种先进的使用链接的) - 的演示的 http://jsfiddle.net/FZ7Xy/

Try this plugin man: called waitforimages plugin: https://github.com/alexanderdickson/waitForImages (scroll down the link you will see various advanced use) - demo http://jsfiddle.net/FZ7Xy/

希望它适合需要:)

code

$('selector').waitForImages(function() {
    // All descendant images have loaded, now slide up.
    $(this).slideUp();  
});
阅读全文

相关推荐

最新文章