-1

I set a background image for a div. But, I want to show the loader up to loading a background image for a <div/> in jQuery.

Erba Aitbayev
  • 4,167
  • 12
  • 46
  • 81
kalles
  • 337
  • 1
  • 6
  • 22

2 Answers2

2

Try like this:

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

Here imgLoader is the image which you want to show when the main image (imgMain) is loading.

Sumanta736
  • 695
  • 3
  • 10
0

You can load an image with jQuery using the load function.

for example:

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