Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Web
Expertise: Beginner
Apr 22, 2002

Use Any Image as a Background


This code allows any image to be used as a background, and scales that image to fit the browser. Just add it to the end of your HTML page:
  
<!-- add this to end of html --> 
<div id="scale_bg"><img name="bgImage" src="scale_bg5.jpg" height="100%" 
width="100%" border="0"></div> 
<script language="JavaScript"> 
<!-- hide script from old browsers 

   if (document.all) { 
      document.all("scale_bg").style.visibility = "visible"; 
      } 
   else if (document.layers) { 
      document.layers["scale_bg"].visibility = "show"; 
      } 

function scaleBG() { 
      if (document.all) { 
                 document.all("scale_bg").style.left = 0; 
         document.all("scale_bg").style.top = 
document.body.scrollTop; 
         document.all("scale_bg").style.width = 
document.body.clientWidth; 
         document.all("scale_bg").style.height = 
document.body.clientHeight; 
         } 
      else if (document.layers) { 
         document.layers["scale_bg"].left = 0; 
         document.layers["scale_bg"].top = window.scrollTop; 
         document.layers["scale_bg"].width = 
window.innerWidth; 
         document.layers["scale_bg"].height = 
window.innerHeight; 
         } 
      setTimeout('scaleBG()',300); 
      } 

if (document.all||document.layers) 
window.onload = scaleBG; 
window.onresize = new Function("scaleBG();"); 
// end hiding from old browsers --> 
</script> 
<style type="text/css"> 
#scale_bg { 
position:absolute; 
z-index:-1; 
left:0; 
top:0; 
visibility:hide; 
visibility:hidden; 
width:40; 
height:40; 
} 
</style> 
Michael Bradley
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date