Here’s a snippet to resize a background image to the dimensions of an element. In this case, #bkgImage.
var resizeBkg = function() {
var h = self.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
var w = self.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
var e = document.getElementById('bkgImage');
if (w > h) {
e.width = w;
e.height = w;
} else {
e.height = h;
e.width = h;
}
}