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

前端之家收集整理的这篇文章主要介绍了jQuery图像预加载在FireFox中第一次不起作用前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我刚刚完成了一个简单的jQuery库,其中有一些淡入淡出的过渡,如here所示.所有浏览器都能正常工作 – 除了“图像预加载”在FireFox的第一次加载时不起作用(适用于所有其他浏览器).图像在Firefox中保持0%的不透明度.不知道为什么.

这是预加载代码.

  1. $(document).ready(function(){
  2. //--------PRELOAD LOAD IMAGES--------\\
  3. $('img').load(function() {
  4. //once image has loaded fade in image
  5. $(this).animate({opacity : 1.0},1000);
  6. //kill padding on last thumbnail of each line
  7. $('#headshots img').eq(3).css({'padding-right' : '0'});
  8. $('#ports img').eq(3).css({'padding-right' : '0'});
  9. $('#ports img').eq(7).css({'padding-right' : '0'});
  10. });
  11. });

在此先感谢您的帮助.

最佳答案
出于好奇,请尝试:

  1. $(this).each(function() {
  2. $(this).animate({opacity : 1.0},1000);
  3. });

为了使您的解决方案更加健壮,您应该考虑在浏览器缓存每个映像时强制为每个映像触发load事件,这可以防止它的load事件被触发.您可以通过测试.complete属性来执行此操作:

  1. $('img').load(function() {
  2. $(this).each(function() {
  3. $(this).animate({opacity : 1.0},1000);
  4. });
  5. $('#headshots img').eq(3).css({'padding-right' : '0'});
  6. $('#ports img').eq(3).css({'padding-right' : '0'});
  7. $('#ports img').eq(7).css({'padding-right' : '0'});
  8. }).each(function() {
  9. if(this.complete) $(this).trigger("load");
  10. });

猜你在找的jQuery相关文章