2012-02-26 48 views
0

下面的代码在本地计算机上工作良好,但在远程服务器上,弹出窗口不考虑滚动宽度,并且出现在页面的顶部,即使当我将页面滚动到底部时。问题只出现在IE中,只出现在远程服务器上。文件是相同的。我应该检查什么?不同行为的弹出窗口css

HTML

<div style="position:absolute;"> 
    <div id="a_div"> 
     123 
    </div> 
</div> 

CSS

#a_div { 
    display:none; 
    position:fixed; 
    width:850px; 
    top:35px; 
    border:1px solid #B1B8C7; 
    background:white; 
    z-index:3000; 
} 

JS

function showaDiv() { 
    var div = document.getElementById('a_div'); 
    var width = document.body.clientWidth; 
    if (div) { 
     div.style.left = Math.round((width-850)/2)+'px'; 
     div.style.display = 'block'; 
     document.getElementById('a_bgdiv').style.display = 'block'; 
    }  
} 
+0

根据你的CSS它应该出现在顶部35px。 – 2012-02-26 09:47:00

+0

为什么它在Firefox和Chrome中运行良好(如我所需)? – Pave 2012-02-26 09:51:51

+0

检查我的答案和小提琴。 – 2012-02-26 10:01:12

回答

0

尝试this fiddle如果要垂直居中

function showaDiv() { 
    var div = document.getElementById('a_div'); 
    var width = document.body.clientWidth; 
    var height = getDocHeight(); 
    if (div) { 
     div.style.left = Math.round((width-850)/2)+'px'; 
     div.style.display = 'block'; 
     div.style.top = Math.round((height-div.clientHeight)/2)+'px'; 
     //document.getElementById('a_bgdiv').style.display = 'block'; 
    }  
} 

function getDocHeight() { 
    var D = document; 
    return Math.max(
     Math.max(D.body.scrollHeight, D.documentElement.scrollHeight), 
     Math.max(D.body.offsetHeight, D.documentElement.offsetHeight), 
     Math.max(D.body.clientHeight, D.documentElement.clientHeight) 
    ); 
} 

刚刚添加了顶部。