Javascript 显示加载程序,直到在jQuery中加载div的背景图像

Javascript 显示加载程序,直到在jQuery中加载div的背景图像,javascript,jquery,html,Javascript,Jquery,Html,我为div设置了背景图像。但是,我想显示加载程序在jQuery中加载的背景图像。您可以使用load函数使用jQuery加载图像 例如: $("<img src='pathtoimg/img.jpg'>").load(function(){ //any code in here will run after the image has successfully loaded. }); $(“”)。加载(函数(){ //这里的任何代码都将在成功加载映像后运行。 }); 试着这样

我为
div
设置了背景图像。但是,我想显示加载程序在jQuery中加载
的背景图像。

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

例如:

$("<img src='pathtoimg/img.jpg'>").load(function(){
    //any code in here will run after the image has successfully loaded.
});
$(“”)。加载(函数(){
//这里的任何代码都将在成功加载映像后运行。
});
试着这样做:

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

这里的imgLoader是加载主映像(imgMain)时要显示的映像。

请写下您尝试了什么?抱歉,我不知道。您是通过jquery加载映像的吗?是的。我通过jquery加载图像。请参阅:我想在加载背景图像之前显示一个加载程序。