码迷,mamicode.com
首页 > 其他好文 > 详细

图片load事件和缓存

时间:2015-06-25 13:43:24      阅读:119      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!