背景图自适应窗口大小

<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>

 

posted on 2017-01-12 16:55  zlix  阅读(97)  评论(0编辑  收藏  举报

导航