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.
Asked
Active
Viewed 614 times
-1

Erba Aitbayev
- 4,167
- 12
- 46
- 81

kalles
- 337
- 1
- 6
- 22
-
please write what have you tried? – Parth Trivedi Jan 29 '16 at 06:50
-
sorry I have no idea. – kalles Jan 29 '16 at 06:52
-
are you loading the image via jquery? – progrAmmar Jan 29 '16 at 06:57
-
yes. i load image through jquery. – kalles Jan 29 '16 at 06:59
-
1Refer: http://stackoverflow.com/questions/4635388/how-to-display-loading-image-while-actual-image-is-downloading and http://network.convergenceservices.in/forum/51-jquery-and-ajax/1865-showing-loader-while-images-are-loading-using-simple-jquery.html – Insane Skull Jan 29 '16 at 07:05
-
you should mention what you tried so far and also search about your problem before asking, there are many possible duplicates of this question already – Deepanshu Goyal Jan 29 '16 at 07:27
2 Answers
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