通过JS弹出的浮动DIV层,居中于窗口中。
<span style="background-color:Gray; width:390px; height:220px; text-align:center;"><BR /><BR />面板中的内容</span>
</div>
<a onclick="javascript:document.all.divCenter.style.display='block';">显示该层</a>
我TT浏览器中,弹出不正常呢?
谁给我写个兼容浏览器的?
完美实现的,加200分!
首先谢谢楼下几位的回答!
我的意思是,如果网页过长的话:
比如在<a onclick="javascript:document.all.divCenter.style.display='block';">显示该层</a>上面加上
100个<BR> 再测试一下。
点击的时候能正常弹出吗? 展开
在CSS里面用expression是只有IE支持的 这就是不兼容的东西
<div id="divCenter" align="center" style="position: absolute; z-index: 3; display: none; background-color: #fff;" >
<span style="background-color:Gray; width:390px; height:220px; text-align:center;"><BR /><BR />面板中的内容</span>
</div>
<script language="JavaScript">
document.getElementById('divCenter').style.left = (document.body.offsetWidth - 540) / 2;
document.getElementById('divCenter').style.top = (document.body.offsetHeight - 170) / 2 + document.body.scrollTop;
</script>
<a onclick="javascript:document.all.divCenter.style.display='block';">显示该层</a>
可以遮挡ie6下的select元素 但是在ie6下div没有透明度;
弹出的div可以一直在浏览器屏幕中间显示 。
代码:
var _CalF = { //便捷方法
$ : function(id){return document.getElementById(id)},
create : function(id){return document.createElement(id)},
append : function(id){return document.body.appendChild(id)},
remove : function(id){return document.body.removeChild(id)}
}
function popup(openID,conID,closeID){
this.onclick(openID,conID,closeID);
}
popup.prototype = {
cssStyle : "width:100%;position:absolute;left:0;top:0;filter:alpha(opacity = 50);opacity:0.5;border:0;overflow:auto;",
createShadowDiv : function(){ //背景遮罩
var shadowDiv = _CalF.create("div");
shadowDiv.id = "shadowDiv";
shadowDiv.style.cssText = this.cssStyle;
shadowDiv.style.height = document.body.scrollHeight + "px";
shadowDiv.style.backgroundColor = "#000"
shadowDiv.style.zindex = 100;
_CalF.append(shadowDiv);
},
createIframe : function(){ //iframe
var iframe = _CalF.create("iframe");
iframe.id = "shadowIframe";
iframe.style.cssText = this.cssStyle;
iframe.style.height = document.body.scrollHeight + "px";
iframe.style.zindex = 99;
_CalF.append(iframe);
},
removeDiv : function(){
_CalF.remove(_CalF.$("shadowDiv"));
_CalF.remove(_CalF.$("shadowIframe"));
},
onclick : function(openID,conID,closeID){
var that = this;
_CalF.$(openID).onclick = function(){
if(window.ActiveXObject){ //ie6
if(!window.XMLHttpRequest){
document.body.style.cssText = "_background-image: url(about:blank);_background-attachment: fixed;";
}
}
that.createIframe();
that.createShadowDiv();
_CalF.$(conID).style.display = "block";
}
document.getElementById(closeID).onclick = function(){
_CalF.$(conID).style.display = "none";
that.removeDiv();
}
}
}
var bt = new popup("bt","orderMsg","close");
</script>
</body>
</html>
if (document.all("div_sb") != null) {
document.body.removeChild(document.all("div_sb"));
}
var divContent = document.createElement("div");
divContent.id = "div_sb";
divContent.style.zIndex = "666666";
divContent.style.position = "absolute";
divContent.style.left = event.clientX;
divContent.style.top = event.clientY;
divContent.style.width = "150px";
divContent.style.Height = "auto";
divContent.style.border = "1px solid";
divContent.style.overflow = "auto";
divContent.style.backgroundColor = "#F7F4EC";
divContent.attachEvent("onmouseout",removeDivContent);
var content +=" <tr><td>"+"面板中的内容"+"</td></tr>";
divContent.innerHTML = "<table>" + content + "</table>";
document.body.insertAdjacentElement("afterBegin", divContent);
divContent.focus();
}
function removeDivContent() {
document.body.removeChild(document.all("div_sb"));
}
楼主牛人呢
个人感觉楼主在做没有意义的事
除非你是腾讯的程序员