The following JS should help:
function resizeBackground()
{
var targetWidth;
var targetHeight;
if (typeof window.innerWidth != 'undefined')
{
targetWidth = window.innerWidth,
targetHeight = window.innerHeight
}
else if (typeof document.documentElement != 'undefined'&& typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0)
{
targetWidth = document.documentElement.clientWidth,
targetHeight = document.documentElement.clientHeight
}
else
{
targetWidth = document.getElementsByTagName('body')[0].clientWidth,
targetHeight = document.getElementsByTagName('body')[0].clientHeight
}
var background = new Image();
background.src = document.getElementById("backgroundImage").src;
var target = document.getElementById("backgroundImage");
var sourceWidth = background.width;
var sourceHeight = background.height;
if (targetWidth / sourceWidth > targetHeight / sourceHeight)
{
target.width = targetWidth;
target.height = sourceHeight * (targetWidth / sourceWidth);
}
else
{
target.width = sourceWidth * (targetHeight / sourceHeight);
target.height = targetHeight;
}
}
window.onload = resizeBackground;
window.onresize = resizeBackground;
Then insert the div wherever you would like you image as so:
<div id= 'backgroundimage'></div>
And finally CSS:
#backgroundimage {background-image:url(image.jpg); width:100%;}