比如说,我做一个弹出窗口 (貌似只能用绝对定位) <div id='pop' class='position:absolute; border:1px solid #b7fb9f; width:200px; z-index:999'>
<h1> 提示 [窗口2秒后消失]</h1>
// content
</div>绝下来,会用Js定位它的Top和Left 值:
比如 var pop=document.getElementById('pop');
pop.style.left=(document.body.clientWidth-pop.clientWidth)/2+document.body.scrollLeft;
pop.style.top=(document.body.clientHeight-pop.clientHeight)/2+document.body.scrollTop;
但这样的效果,并且如 alert('something') 弹出窗口那样 可以居中。特别,比如页面内容比较长, 我用了 MaintainScrollPositionOnPostback="true" postback后保持 ScrollPosition,
弹出窗口 就会出现很顶部(看不到的地方),因为其top值没有加上 ScrollPosition部分的值。
请问各位大侠,要怎样才能让弹出的窗口,无论什么情形,都好像 alert()弹出窗口那样,可以居中显示呢?? 非常感谢!!
<h1> 提示 [窗口2秒后消失]</h1>
// content
</div>绝下来,会用Js定位它的Top和Left 值:
比如 var pop=document.getElementById('pop');
pop.style.left=(document.body.clientWidth-pop.clientWidth)/2+document.body.scrollLeft;
pop.style.top=(document.body.clientHeight-pop.clientHeight)/2+document.body.scrollTop;
但这样的效果,并且如 alert('something') 弹出窗口那样 可以居中。特别,比如页面内容比较长, 我用了 MaintainScrollPositionOnPostback="true" postback后保持 ScrollPosition,
弹出窗口 就会出现很顶部(看不到的地方),因为其top值没有加上 ScrollPosition部分的值。
请问各位大侠,要怎样才能让弹出的窗口,无论什么情形,都好像 alert()弹出窗口那样,可以居中显示呢?? 非常感谢!!
margin-top:-120px;试下这两个属性吧
1,视框宽度减去高亮层宽度的一半就是居中需要的left值;
2,先设置left值为50%,然后marginLeft设为负的高亮层宽度的一半。参考这里的居中显示部分