var mybg = document.createElement("div");
    //弹出层
    function d_x(){  
         
    var h = document.body.clientHeight; 
    var w = document.body.clientWidth;
       
    myAlert = document.getElementById("alert"); 
    myAlert.style.display = "block";  
    myAlert.style.position = "absolute";
     
    
    myAlert.style.top = (h/2)+"px";  
    myAlert.style.left = (w/2)+"px";  
    //myAlert.style.marginTop = "-200px";  
    //myAlert.style.marginLeft = "-250px";  
    
    mybg.setAttribute("id","mybg");  
    mybg.style.background = "#000";
    mybg.style.display = "block";     mybg.style.width = "100%"; 
    mybg.style.height = h+"px";  
    mybg.style.position = "absolute";  
    mybg.style.top = "0";  
    mybg.style.left = "0";  
    mybg.style.zIndex = "500";  
    mybg.style.opacity = "0.5";  
    mybg.style.filter = "Alpha(opacity=40)";  
    document.body.appendChild(mybg);  
    document.body.style.overflow = "hidden";   

解决方案 »

  1.   

        //myAlert.style.position = "absolute";
        myAlert.style.position = "fixed";  //不过对IE6-不起作用,你需要使用计时器移动层
      

  2.   

    myAlert这个的zIndex是多少?被mybg这个曾给遮盖住了吧。。
      

  3.   

    我没设置myAlert 中 zIndex的值。是不是要设置比mybg的值大一些
      

  4.   

    $(window).bind("scroll",function(){改层的位置})
      

  5.   

    恩fixed和absolute一样的,通过z-index设置显示循序,大的显示最上面。只是fixed滚动后相对窗口位置不变
      

  6.   


     //myAlert.style.position = "absolute";
        myAlert.style.position = "fixed"; 
    我这样写了以后。在IE6里面,层上的东西和层的模糊度一样了。不能点击,这是为什么。我将myAlert里面的zIndex设置为1000还是不行。
      

  7.   

    $(window).bind("scroll",function(){
         var h = document.body.clientHeight; 
         document.getElementById('alert').style.top = (h/2+document.body.scrollHeight)+'px';
    })
      

  8.   

    ie6不支持position:fixed.写特例吧
    可以看看这个http://www.cnblogs.com/hooray/archive/2011/05/20/2052269.html
      

  9.   

    谢谢大家。我直接在js中判断当前浏览器版本if(isIE){
      if(isIE6){
        myAlert.style.position = "absolute";
         }
      }
      else{
       myAlert.style.position = "fixed";
      }问题解决了。结贴
      

  10.   

    添加滚动条事件,当它移动的时候
    top=document.documentElement.scrollTop