jQuery图像预加载在FireFox中第一次不起作用

Mea*_*att 5 firefox jquery jquery-animate

我刚刚完成组建了一个简单的jQuery画廊有些褪色的转变所看到这里.在所有浏览器中一切正常 - 除了"图像预加载"在FireFox的第一次加载时不起作用(适用于所有其他浏览器).图像在Firefox中保持0%的不透明度.不知道为什么.

这是预加载代码.

$(document).ready(function(){
    //--------PRELOAD LOAD IMAGES--------\\
    $('img').load(function() {
        //once image has loaded fade in image
        $(this).animate({opacity : 1.0}, 1000);

        //kill padding on last thumbnail of each line
        $('#headshots img').eq(3).css({'padding-right' : '0'});
        $('#ports img').eq(3).css({'padding-right' : '0'});
        $('#ports img').eq(7).css({'padding-right' : '0'});
    });
});
Run Code Online (Sandbox Code Playgroud)

在此先感谢您的帮助.

kar*_*m79 3

出于好奇,尝试一下:

$(this).each(function() {
    $(this).animate({opacity : 1.0}, 1000);
});
Run Code Online (Sandbox Code Playgroud)

为了使您的解决方案更加健壮,您应该考虑在浏览器缓存了每个图像的情况下强制触发加载事件,这可以防止触发加载事件。您可以通过测试该.complete属性来做到这一点:

$('img').load(function() {
    $(this).each(function() {
        $(this).animate({opacity : 1.0}, 1000);
    });
    $('#headshots img').eq(3).css({'padding-right' : '0'});
    $('#ports img').eq(3).css({'padding-right' : '0'});
    $('#ports img').eq(7).css({'padding-right' : '0'});
}).each(function() {
    if(this.complete) $(this).trigger("load");
});
Run Code Online (Sandbox Code Playgroud)