繁体   English   中英

如何显示加载的gif图像,直到加载大图像?

[英]How to display loading gif image until the big image have loaded?

我在做什么错?它没有显示gif。 不一定是div内任何图像的元素

   $('#loadbig a').each(function(index,el){

       //find this link's child image element
      var img = $(this).find('img');

      //hide the image and attach the load event handler
      $(img).hide().load(function () {

            //remove the link's "loading" classname
            $(el).removeClass('loading');

            //show the loaded image
            $(img).fadeIn();
      })
});

CSS:

#loadbig a.loading{
    background:url(images/loading.gif) no-repeat center center;
}

锚点是没有高度的嵌入式元素,因此不会显示背景图像。

更好地将加载的gif显示为图像本身并隐藏onload

$('#loadbig a').each(function(index,el){

   //find this link's child image element
  var img = $(this).find('img.bigImage');
  var loading = $(this).find('img.loading');

  //hide the image and attach the load event handler
  $(img).hide().load(function () {

        //hide loading gif
        $(loading).hide();

        //show the loaded image
        $(img).fadeIn();
  })

});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM