【问题标题】:Show the loader upto loading the background image for a div in jQuery在 jQuery 中显示加载器以加载 div 的背景图像
【发布时间】:2016-01-29 15:16:38
【问题描述】:

我为div 设置了背景图片。但是,我想展示加载器在 jQuery 中为 <div/> 加载背景图像。

【问题讨论】:

标签: javascript jquery html


【解决方案1】:

试试这样:

$(document).ready(function(){
  $('#imgLoader').show();
  $('#imgMain').load(function(){
    $('imgLoader').hide();
  });
});

这里的imgLoader是你想在加载主图像(imgMain)时显示的图像。

【讨论】:

    【解决方案2】:

    您可以使用 jQuery 使用 load 函数加载图像。

    例如:

    $("<img src='pathtoimg/img.jpg'>").load(function(){
        //any code in here will run after the image has successfully loaded.
    });
    

    【讨论】:

    • 我想在背景图片加载之前显示一个加载器。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-05-29
    • 1970-01-01
    • 1970-01-01
    • 2014-05-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多