oaktree6
11-11-2010, 11:12 PM
Hi CodingForum!
For my website, I have a working script that changes the background image of my website every time it is reloaded. However, I would also like the image to dynamically resize as the user resizes the browser window.
here is a code snippet:
<head>
<script type="text/JavaScript">
/*<![CDATA[*/var el="bgImg";var bgimg=new Array("../00home/06home.jpg","../00home/07home.jpg");var random=Math.round((bgimg.length-1)*Math.random());var cssStr="#"+el+" { background: url("+bgimg[random]+") no-repeat center } ";var style=document.createElement("style");style.setAttribute("type","text/css");if(style.styleSheet){style.styleSheet.cssText=cssStr;}else{var cssText=document.createTextNode(cssStr);style.appendChild(cssText);}document.getElementsByTagName("head")[0].appendChild(style);/*]]>*/
</script>
<style type="text/css">
.rotatebg {
z-index:0;
position:fixed;
top:0; left:0;
width:1378px; height:1178px;
background-repeat: no-repeat;
background-position:inherit;
overflow:hidden;
}
</style>
</head
<body>
<div class="rotatebg" id="bgImg" style="width:100%; height:100%" ></div>
</body>
Does anyone know how I can augment/alter this coded setup to enable the randomly loaded background image to proportionately fill the browser window? :o
For my website, I have a working script that changes the background image of my website every time it is reloaded. However, I would also like the image to dynamically resize as the user resizes the browser window.
here is a code snippet:
<head>
<script type="text/JavaScript">
/*<![CDATA[*/var el="bgImg";var bgimg=new Array("../00home/06home.jpg","../00home/07home.jpg");var random=Math.round((bgimg.length-1)*Math.random());var cssStr="#"+el+" { background: url("+bgimg[random]+") no-repeat center } ";var style=document.createElement("style");style.setAttribute("type","text/css");if(style.styleSheet){style.styleSheet.cssText=cssStr;}else{var cssText=document.createTextNode(cssStr);style.appendChild(cssText);}document.getElementsByTagName("head")[0].appendChild(style);/*]]>*/
</script>
<style type="text/css">
.rotatebg {
z-index:0;
position:fixed;
top:0; left:0;
width:1378px; height:1178px;
background-repeat: no-repeat;
background-position:inherit;
overflow:hidden;
}
</style>
</head
<body>
<div class="rotatebg" id="bgImg" style="width:100%; height:100%" ></div>
</body>
Does anyone know how I can augment/alter this coded setup to enable the randomly loaded background image to proportionately fill the browser window? :o