标签:
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事件不会被触发两次。
标签:
原文地址:http://www.cnblogs.com/unreal-world/p/4599628.html