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

陌城灬流年閣 2012-08-14 03:51:11



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";
...全文
374 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
hhh305743261 2012-08-15
  • 打赏
  • 举报
回复
添加滚动条事件,当它移动的时候
top=document.documentElement.scrollTop
陌城灬流年閣 2012-08-15
  • 打赏
  • 举报
回复
谢谢大家。我直接在js中判断当前浏览器版本

if(isIE){
if(isIE6){
myAlert.style.position = "absolute";
}
}
else{
myAlert.style.position = "fixed";
}

问题解决了。结贴
陌城灬流年閣 2012-08-15
  • 打赏
  • 举报
回复
[Quote=引用 14 楼 的回复:]

滚动的时候弹出层跟着一起滚
[/Quote]

是居中的吗
tptptp00 2012-08-15
  • 打赏
  • 举报
回复
滚动的时候弹出层跟着一起滚
陌城灬流年閣 2012-08-15
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 的回复:]

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

这样写以后效果是什么
如流风般凌乱 2012-08-15
  • 打赏
  • 举报
回复
ie6不支持position:fixed.写特例吧
可以看看这个http://www.cnblogs.com/hooray/archive/2011/05/20/2052269.html
tptptp00 2012-08-15
  • 打赏
  • 举报
回复
$(window).bind("scroll",function(){
var h = document.body.clientHeight;
document.getElementById('alert').style.top = (h/2+document.body.scrollHeight)+'px';
})
陌城灬流年閣 2012-08-14
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 的回复:]

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

能再详细点吗
陌城灬流年閣 2012-08-14
  • 打赏
  • 举报
回复

//myAlert.style.position = "absolute";
myAlert.style.position = "fixed";


我这样写了以后。在IE6里面,层上的东西和层的模糊度一样了。不能点击,这是为什么。我将myAlert里面的zIndex设置为1000还是不行。
Go 旅城通票 2012-08-14
  • 打赏
  • 举报
回复
恩。。。fixed和absolute一样的,通过z-index设置显示循序,大的显示最上面。只是fixed滚动后相对窗口位置不变
tptptp00 2012-08-14
  • 打赏
  • 举报
回复
$(window).bind("scroll",function(){改层的位置})
陌城灬流年閣 2012-08-14
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 的回复:]

myAlert这个的zIndex是多少?被mybg这个曾给遮盖住了吧。。
[/Quote]
我没设置myAlert 中 zIndex的值。是不是要设置比mybg的值大一些
Go 旅城通票 2012-08-14
  • 打赏
  • 举报
回复
myAlert这个的zIndex是多少?被mybg这个曾给遮盖住了吧。。
陌城灬流年閣 2012-08-14
  • 打赏
  • 举报
回复
自己顶下。求解
陌城灬流年閣 2012-08-14
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]

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

这个在IE上面运行以后,遮罩层中的内容不能选择
陌城灬流年閣 2012-08-14
  • 打赏
  • 举报
回复
嗯,我先试下。
Go 旅城通票 2012-08-14
  • 打赏
  • 举报
回复
    //myAlert.style.position = "absolute";
myAlert.style.position = "fixed"; //不过对IE6-不起作用,你需要使用计时器移动层

87,921

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧