图像加载事件在IE7 / 8中随机触发
|
情况:
我正在使用javascript调整大小/预加载图像,然后在页面上显示它们。
问题:
ie7 / 8倾向于随机触发某些图像而不是其他图像的加载事件(这是完全随机的,每次刷新都不同)
码:
JS:
$(document).ready(function(){
$(\".daImg\").hide();
$(\"figure\").each(function(){
$(this).append(\'<div class=\"loader\"><img src=\"images/ajax-loader.gif\"></div>\');
var afb = $(this).find(\".daImg\");
afb.load(function(){
console.log(\"loaded\");
$(this).parent().parent().parent().find(\".loader\").remove();
if($(this).parent().parent().parent().is(\".last\")){
if(afb.height() > 280){
var w = (afb.width()/afb.height())*280
afb.css(\"width\",w);
afb.css(\"height\",\"280px\");
}
} else {
if(afb.height() > 245){
var w = (afb.width()/afb.height())*245
afb.css(\"width\",w);
afb.css(\"height\",\"245\");
}
}
afb.css(\"left\",\"50%\");
afb.css(\"margin-left\",\"-\"+afb.width()/2+\"px\");
afb.fadeIn();
})
});
}
的HTML
<figure class=\"left\">
<a href=\"foobar.html\">
<div class=\"imageWrap\">
<img class=\"daImg\" src=\"foo-bar.png\" alt=\"foobar\" />
</div>
<figcaption class=\"cufonize\"><span class=\"decorated\">foobar</span><br>
<span class=\"price\">99</span>
</figcaption>
</a>
<figure class=\"left\">
<a href=\"foobar.html\">
<div class=\"imageWrap\">
<img class=\"daImg\" src=\"foo-bar.png\" alt=\"foobar\" />
</div>
<figcaption class=\"cufonize\"><span class=\"decorated\">foobar</span><br>
<span class=\"price\">99</span>
</figcaption>
</a>
<figure class=\"left\">
<a href=\"foobar.html\">
<div class=\"imageWrap\">
<img class=\"daImg\" src=\"foo-bar.png\" alt=\"foobar\" />
</div>
<figcaption class=\"cufonize\"><span class=\"decorated\">foobar</span><br>
<span class=\"price\">99</span>
</figcaption>
</a>
<figure class=\"left\">
<a href=\"foobar.html\">
<div class=\"imageWrap\">
<img class=\"daImg\" src=\"foo-bar.png\" alt=\"foobar\" />
</div>
<figcaption class=\"cufonize\"><span class=\"decorated\">foobar</span><br>
<span class=\"price\">99</span>
</figcaption>
</a>
<figure class=\"left\">
<a href=\"foobar.html\">
<div class=\"imageWrap\">
<img class=\"daImg\" src=\"foo-bar.png\" alt=\"foobar\" />
</div>
<figcaption class=\"cufonize\"><span class=\"decorated\">foobar</span><br>
<span class=\"price\">99</span>
</figcaption>
</a>
如果有人能对这里发生的事情有所了解,我将不胜感激!
注意:此问题与缓存无关,因为我正在为实际代码中的所有图像添加时间戳。
没有找到相关结果
已邀请:
1 个回复
呈辖玫割善
然后将图像大小调整脚本挂在$(window).load();上 并立即处理所有图像:not(:visible) 您也可以将其余浏览器的内容复制到img.load事件,但不包含已复制的图像。我的意思是您的选择者是
; 在这种情况下,IE将处理所有其他事件未处理的图像