Well, the title pretty much describes my question:
How to load a background image dynamically after it is fully loaded? Sometimes I have to use backgrounds that are so large that the browser may take some time to load it. I would prefer to “download it in the background” and let it disappear when it is fully loaded.
I think jQuery is best used, but I also need my background if JavaScript is disabled. If this is really impossible, so be it, but I think it is?
Regards, Aart
........
EDIT:
Thanks guys! I have been looking for this for a long time and simply could not come up with a good and easy way.
I converted Jeffrey's Javascript solution to jQuery, just because jQuery's built-in fading looks so awesome.
I will just post it here if someone else has the same problem:
<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js'></script> <script type='text/javascript'> $(document).ready(function() { $('#img').css('opacity','0').load(function() { $(this).animate({ opacity: 1 }, 500); }); }); </script> <img src='yourimage.jpg' id='img'/>
source share