I have an element that serves as the banner on my website. This banner has HTML content on it, but uses a high-resolution picture as the background-image. Because of this, I’m loading the background-image last and fading it in when it has been downloaded. My code looks like this:
<table id="bannerTable" border="0" cellpadding="0" cellspacing="0" style="width:640px; height:480px;">
<tr><td style="padding-top:20px; padding-left:300px;">
<div>[Some Text]</div>
</td></tr>
<tr><td style="vertical-align:bottom; padding-bottom:20px;">
<div>[Site Menu Goes Here]</div>
</td></tr>
</table>
<script type="text/javascript">
$(document).ready(function () {
$("#bannerTable").loadBGImage("/picture1.png");
});
$.fn.loadBGImage = function (url) {
var t = this;
$('<img />')
.attr('src', url)
.load(function () {
t.each(function () {
$(this).hide();
$(this).css('backgroundImage', 'url(' + url + ')');
$(this).fadeIn();
});
});
return this;
}
</script>
Even with this, my website feels static. Because of this, I want to loop through multiple high-resolution images at runtime. These high-resolution images will be used in the bannerTable as the background-image. I want them to fade-in and fade-out as they loop.
How do I do this with jQuery?
look the demo source for the full working code