jQuery的替代绑定('LOAD')与图像的使用 [英] jQuery alternative to bind('load') for use with images

查看:175
本文介绍了jQuery的替代绑定('LOAD')与图像的使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
  <一href="http://stackoverflow.com/questions/3877027/jquery-callback-on-image-load-even-when-the-image-is-cached">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();  
});

这篇关于jQuery的替代绑定('LOAD')与图像的使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆