-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
  • 3,937
  • 11
  • 45
  • 77
kalles
  • 327
  • 1
  • 5
  • 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
  • 685
  • 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.
});
FirstLegion
  • 671
  • 6
  • 19