js问题,当窗口变化时,如何让页面也跟着变就像GMail一样的。就像是有些页面里的div是用的绝对定位。如果让这个也改变在窗口里的绝对位置。

解决方案 »

  1.   

    而且好像GMail还不能查看源代码,有没有人知道是怎么回事?
      

  2.   

    界面大小改变会触发事件
    window.onresize = function(){ 
    follow();
    };
    function follow(){
    //自己写需要执行的方法如改变Div位置
    }
      

  3.   


    为什么 window.onresize 调用时 follow();会执行三次?
      

  4.   

    window.onload = function() {
        if (!window.event) return;
        var bgimg = document.getElementById("bgimg");
        window.onresize = function() {
            bgimg.style.width = document.body.clientWidth + "px";
            bgimg.style.height = document.body.clientHeight + "px";
        };
        window.onresize();
    }
    背景图片大小随窗口大小变化,参考下
      

  5.   


    function resizeLogin(id){
    document.getElementById(id).style.top=(document.documentElement.offsetHeight/2 || document.documentElement.scrollHeight/2||document.body.scrollHeight/2||document.body.offsetHeight/2) -251 + "px";document.getElementById(id).style.left=(document.documentElement.offsetWidth/2 || document.documentElement.scrollWidth/2||document.body.scrollWidth/2||document.body.scrollWidth/2) -252 + "px";
    document.getElementById(id).style.display="block";
    }
    <body onresize="resizeLogin(***);" onload="resizeLogin(***);">
       <div id=***>
    </div>
    </body>