js实现背景图自适应窗口大小

原创 2017-01-14 11:27:15 353
摘要:本文分享了背景图自适应窗口大小的实例代码<script type="text/javascript">  window.onresize = window.onload = function()  {   var w,bgImg;   if(!!(

本文分享了背景图自适应窗口大小的实例代码

<script type="text/javascript">
 window.onresize = window.onload = function()
 {
  var w,bgImg;
  if(!!(window.attachEvent && !window.opera)) {
   w = document.documentElement.clientWidth;
  } else {
   w = window.innerWidth;
  }if(w>1650){
   document.getElementById ('msg').value ='窗口大小:' + 'width:' + w;
   bgImg = document.getElementById('bg').getElementsByTagName('img')[0];
   bgImg.width = (w - 5);
  }else{
  document.getElementById ('msg').value ='窗口大小:' + 'width:' + w;
  bgImg = document.getElementById('bg').getElementsByTagName('img')[0];
  bgImg.width = 1650;
 }
 }
</script>

 更多关于js实现背景图自适应窗口大小请关注PHP中文网(www.php.cn)其他文章!

发布手记

热门词条