js 弹出层

今天在整理代码的时候找到了去年从一个同事手里收集到的一个挺不错的JS弹出层,呵呵,废话不多说,贴代码。



<html>
<head>
<title>JS弹出窗口</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head>
<script>
//测试DAlert对象
var dc;
function Show1(){
//创建提示框内容部分
var d = document.createElement_x("div"); //创建主要显示DIV
d.style.width="560px"; //DIV样式设置
d.style.height="300px";
d.style.backgroundColor="#999";
d.style.padding="10px";
//向提示框内容部分画需要显示的信息
d.innerHTML="<div style='float:left;font-weight:bold;height:20px;line-height:20px; width:550px;font-size:12px'><span style='float:left;'>网站小统计</span><a href='javascript:;' style='float:right;' οnclick=\"Hide1()\">关闭窗口</a></div><div><iframe frameborder='0' id='kj' name='kj' style='width:540px;height:280px;' scrolling='no' src=\'http://www.yasuoji120.com\'/> </iframe></div>";//DIV内容

//实例化提示框
dc = new DAlert(d);
//显示提示框
dc.show();
}

//提示框里的Button按钮点击事件
function Hide1(){
//移除对话框
dc.remove(); //移除DIV
}

function DAlert(mesDIV){
this.mesDIV=mesDIV;
//创建提示框底层
this.boDIV = document.createElement_x("div");
//获取body中间点
var x=document.body.clientWidth/2,y=document.body.clientHeight/2;
//配置样式
this.boDIV.style.opacity="0.50";
this.boDIV.style.filter="Alpha(opacity=50);";
this.boDIV.style.backgroundColor="#CCCCCC";
this.boDIV.style.height="100%";
this.boDIV.style.width="100%";
this.boDIV.style.marginTop="0px";
this.boDIV.style.marginLeft="0px";
this.boDIV.style.position="absolute";
this.boDIV.style.top="0px";
this.boDIV.style.left="0px";
this.boDIV.style.zIndex=100;

//显示提示框
this.show = function(){
//显示提示框底层
document.body.appendChild(this.boDIV);
//显示mesDIV
document.body.appendChild(this.mesDIV);
//把mesDIV定位到body中间
this.mesDIV.style.position="absolute";//设置弹出层为绝对定位
x=x-this.mesDIV.clientWidth/2;

y=y-this.mesDIV.clientHeight/2;

this.mesDIV.style.top=y+"px"; //距离网页头部距离
this.mesDIV.style.left=x+"px"; //左边距离
this.mesDIV.style.zIndex=101; //Zindex参数,在css里写做z-index
}

//移除提示框
this.remove = function(){
document.body.removeChild(this.boDIV);
document.body.removeChild(this.mesDIV);
}
}
</script>
<body>
<a href="#" onClick="Show1()">点击我啊进入易迅制冷资讯网</a>

</body>
</html>



代码经测试,在IE6,7,8 ,firefox,chrome浏览器均可使用。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值