Javascript IE7/8中随机触发的图像加载事件

Javascript IE7/8中随机触发的图像加载事件,javascript,html,internet-explorer-8,load,internet-explorer-7,Javascript,Html,Internet Explorer 8,Load,Internet Explorer 7,情况: 在页面上显示图像之前,我正在使用javascript调整图像大小/预加载图像 问题: ie7/8倾向于随机触发某些图像的加载事件,而不是其他图像的加载事件(这是完全随机的,每次刷新时都会有所不同) 代码: JS: $(文档).ready(函数(){ $(“.daImg”).hide(); $(“数字”)。每个(函数(){ $(此)。附加(“”); var afb=$(this.find(“.daImg”); afb.load(函数(){ 控制台日志(“已加载”); $(this.pare

情况:

在页面上显示图像之前,我正在使用javascript调整图像大小/预加载图像

问题:

ie7/8倾向于随机触发某些图像的加载事件,而不是其他图像的加载事件(这是完全随机的,每次刷新时都会有所不同)

代码:

JS:

$(文档).ready(函数(){
$(“.daImg”).hide();
$(“数字”)。每个(函数(){
$(此)。附加(“”);
var afb=$(this.find(“.daImg”);
afb.load(函数(){
控制台日志(“已加载”);
$(this.parent().parent().parent().find(“.loader”).remove();
如果($(this.parent().parent().parent()是(“.last”)){
如果(afb高度()>280){
变量w=(afb.width()/afb.height())*280
afb.css(“宽度”,w);
afb.css(“高度”、“280px”);
}
}否则{
如果(afb高度()>245){
var w=(afb.width()/afb.height())*245
afb.css(“宽度”,w);
afb.css(“高度”、“245”);
}
}
afb.css(“左”、“50%”);
css(“左边距”,“-”+afb.width()/2+“px”);
afb.fadeIn();
})
});
}
HTML






如果有人能告诉我这里发生了什么,我将不胜感激


注意:这个问题与缓存无关,因为我在实际代码中为所有图像添加了时间戳。

您可以尝试不同的方法

使用css

.daImg {
   display:none;
}
然后将图像大小调整脚本挂接到$(window.load(); 并同时操作所有图像:不(:可见)

对于rest浏览器,您也可以将其复制到img.load事件,但对于尚未可见的图像,我的意思是您的选择器为
var afb=$(this).find(“.daImg:not(:visible)”)


在这种情况下,即未被其他事件处理的所有图像都将在那里处理

您可以在您的情况下尝试不同的方法

使用css

.daImg {
   display:none;
}
然后将图像大小调整脚本挂接到$(window.load(); 并同时操作所有图像:不(:可见)

对于rest浏览器,您也可以将其复制到img.load事件,但对于尚未可见的图像,我的意思是您的选择器为
var afb=$(this).find(“.daImg:not(:visible)”)


在这种情况下,IE会处理其他事件未处理的所有图像

这是IE的一个已知问题,对于缓存的图像,onload do not fire
。最近的(选择器)
将帮助清理
.parent().parent().parent()中的代码
etc它们不是缓存的。它们实际上是加载的,事件似乎不会发生。要添加到venimus,如果是这种情况,请在图像路径的末尾放置一个随机查询字符串,以强制重新加载到我当前用于防止缓存的系统中,并在查询中添加时间戳,请参阅“注意:IE存在一个众所周知的问题,onload不为缓存的图像触发
。最近的(选择器)
将帮助清理
.parent().parent().parent()中的代码
etc它们不是缓存的。它们实际上是加载的,事件似乎不会发生。要添加到venimus,如果是这种情况,请在图像路径的末尾放置一个随机查询字符串,以强制重新加载到我当前用于防止缓存的系统中,并在查询中添加时间戳,请参阅“注意:当涉及IE时,解决方案通常不漂亮:)当涉及IE时,解决方案通常不漂亮:)
<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>
.daImg {
   display:none;
}