//本文支持js線上工具測試、轉載請註明出處。 UntitledDocument 點我點我 username:u p w d: 點我點我 出處:http://blog.csdn.net/xuexiaodong009/article/details/66054...
//本文支持js線上工具測試、轉載請註明出處。
<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"/>
<title>UntitledDocument</title>
<script>
function openDiv(newDivID)
{
var newMaskID = "mask"; //遮罩層id
var newMaskWidth =document.body.scrollWidth;//遮罩層寬度
var newMaskHeight =document.body.scrollHeight;//遮罩層高度
//mask遮罩層
var newMask = document.createElement("div");//創建遮罩層
newMask.id = newMaskID;//設置遮罩層id
newMask.style.position = "absolute";//遮罩層位置
newMask.style.zIndex = "1";//遮罩層zIndex
newMask.style.width = newMaskWidth + "px";//設置遮罩層寬度
newMask.style.height = newMaskHeight + "px";//設置遮罩層高度
newMask.style.top = "0px";//設置遮罩層於上邊距離
newMask.style.left = "0px";//設置遮罩層左邊距離
newMask.style.background = "gray";//#33393C//遮罩層背景色
newMask.style.filter = "alpha(opacity=40)";//遮罩層透明度IE
newMask.style.opacity = "0.40";//遮罩層透明度FF
document.body.appendChild(newMask);//遮罩層添加到DOM中
window.open('http://www.baidu.com','_blank','width=500,height=260,menubar=no,toolbar=no'); //彈出子頁面,具體自用自改//彈出層滾動居中
function newDivCenter()
{
newDiv.style.top = (document.body.scrollTop + document.body.clientHeight/2
- newDivHeight/2) + "px";
newDiv.style.left = (document.body.scrollLeft + document.body.clientWidth/2
- newDivWidth/2) + "px";
}
if(document.all)//處理滾動事件,使彈出層始終居中
{
window.attachEvent("onscroll",newDivCenter);
}
else
{
window.addEventListener('scroll',newDivCenter,false);
}
//關閉新圖層和mask遮罩層
var newA = document.createElement("span");
newA.href = "#";
newA.style.position = "absolute";//span位置
newA.style.left=350+ "px";
newA.innerHTML = "Close";
newA.onclick = function()//處理關閉事件
{
if(document.all)
{
window.detachEvent("onscroll",newDivCenter);
}
else
{
window.removeEventListener('scroll',newDivCenter,false);
}
document.body.removeChild(newMask);//移除遮罩層
document.body.removeChild(newDiv);////移除彈出框
return false;
}
newDiv.appendChild(newA);//添加關閉span
}
</script>
</head><BODY>
<a onclick="openDiv('newDiv');" style="cursor:pointer">點我點我</a>
<br>
username:<input type="text" name="uname"/><br>
u p w d:<input type="password" name="upwd"/>
<br /><br /><br /><br /><br /><br />
<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
<br /><br /><br /><br /><br /><br />
<a onclick="openDiv('newDiv');" style="cursor:pointer">點我點我</a>
</BODY>
</html>
出處:http://blog.csdn.net/xuexiaodong009/article/details/6605417
參考文檔:http://blog.csdn.net/alex197963/article/details/4456174