I have an image loading that is resize to fit the window using javascript, and the image is continuously resize when the browser window is resized. However, before the javascript resize the image is loaded full-size. So you see the full-size image and then it jumps to the resized version. Can I fix this so only the resized image is loaded?
I've hacked a small work around where I make the image visibility:hidden and then after the javascript resize I set the visibility:visible but this is not the most ideal solution.
Any help would be superb, thanks.
HTML
<body>
<img style="content:url(/uploads/user/bg_image/31/background.jpg) no-repeat fixed left top;" id="bg">
</body>
JAVASCRIPT
$(window).load(function() { var theWindow = $(window), $bg = $("#bg"), aspectRatio = $bg.width() / $bg.height(); function resizeBg() { if ( (theWindow.width() / theWindow.height()) < aspectRatio ) { $bg .removeClass() .addClass('bgheight'); } else { $bg .removeClass() .addClass('bgwidth'); } } theWindow.resize(function() { resizeBg(); }).trigger("resize"); });