首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

js抢救,等。怎样让弹出层锁定居中。不随滚动条滚动而改变位置

2012-08-29 
js急救,等。怎样让弹出层锁定居中。不随滚动条滚动而改变位置。JScript codevar mybg document.createEleme

js急救,等。怎样让弹出层锁定居中。不随滚动条滚动而改变位置。

JScript code
            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";   


[解决办法]
JScript code
    //myAlert.style.position = "absolute";    myAlert.style.position = "fixed";  //不过对IE6-不起作用,你需要使用计时器移动层
[解决办法]
$(window).bind("scroll",function(){改层的位置})
[解决办法]
ie6不支持position:fixed.写特例吧
可以看看这个http://www.cnblogs.com/hooray/archive/2011/05/20/2052269.html

热点排行