首页 > 其他 > 详细

图片load事件和缓存

时间:2015-06-25 13:42:59      阅读:209      评论:0      收藏:0      [点我收藏+]

 

If the src is already set, then the event is firing in the cached case, before you even get the event handler bound. To fix this, you can loop through checking and triggering the event based off .complete, like this:

$("img").one("load", function() {
  // do stuff
}).each(function() {
  if(this.complete) $(this).load();
});

Note the change from .bind() to .one() so the event handler doesn‘t run twice. 

==================================================================

如果图片在缓存中,它的load事件早在你绑定之前就已经被触发了。

为了避免这种情况,你可以对每一张图片检测.complete属性,然后主动触发load事件。

注意这里用的是.one()而不是.bind()或者.on(),这样load事件不会被触发两次。

 

图片load事件和缓存

原文:http://www.cnblogs.com/unreal-world/p/4599628.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!