function runIt() {
winprop = $(window).height() / $(window).width();
var bgprop = $("#bgimg").height() / $("#bgimg").width();
if(winprop < bgprop)
{
    $("#bgimg").css({
    width: $(window).width(),
    height: "auto"
    })
} else {
    $("#bgimg").css({
    width: "auto",
    height: $(window).height()
    })
  }
}
function doSomething() {
alert("I'm done resizing for the moment");
};
runIt();
var resizeTimer = null;
$(window).bind('resize', function() {
if (resizeTimer) clearTimeout(resizeTimer);
resizeTimer = setTimeout(runIt, 20);
});
将bg图像赋予它自己的ID。更改图像的大小,而不是DIV。