我现在在做一个弹出层,同时背景变暗的功能,功能是实现了,但是如果浏览器不是在最大化状态,背景色的大小也会和浏览器的大小一致,此时一旦把浏览器最大化,大小也就那么点大。
我的JS代码 this.createBgLayer=function()
{
bgLayer = document.createElement("div");
with (bgLayer)
{
className="bgLayer";
style.width=documentHtml.scrollWidth+"px";
style.height=documentHtml.scrollHeight+"px";
style.display="none";
}
document.body.insertBefore(bgLayer,document.body.firstChild);
};   求解决方法

解决方案 »

  1.   

     if(window.addEventListener){                window.addEventListener('resize', function(e){setDivSize();  },false); 
                }else{ 
                   window.attachEvent("onresize",function(){ setDivSize(); });        
                }function setDivSize(){
    bgLayer.style.width=documentHtml.scrollWidth+"px";
    bgLayer.style.height=documentHtml.scrollHeight+"px";
    }
      

  2.   

    this.createBgLayer=function()
    {
    bgLayer = document.createElement("div");
    with (bgLayer)
    {
    id="我罩你";//加上这条
    className="bgLayer";
    style.width=documentHtml.scrollWidth+"px";
    style.height=documentHtml.scrollHeight+"px";
    style.display="none";
    }
    document.body.insertBefore(bgLayer,document.body.firstChild);
    };function 调整遮罩大小(){
    var o=document.getElementById('我罩你');
    o.style.width=documentHtml.scrollWidth+"px";
    o.style.height=documentHtml.scrollHeight+"px";
    }
    window.onresize=调整遮罩大小;