jquery弹出层

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>可以拖动的居中弹出层-懒人建站-51xuediannao.com</title>

<script language="javascript">
function alertWin(title, msg, w, h){
var titleheight = "22px"; //提示窗口标题高度
var bordercolor = "#666699"; //提示窗口的边框颜色
var titlecolor = "#FFFFFF"; //提示窗口的标题颜色
var titlebgcolor = "#666699";
var bgcolor = "#FFFFFF";
var iWidth = document.documentElement.clientWidth;
var iHeight = document.documentElement.clientHeight;
var bgObj = document.createElement("div");
bgObj.id = "BgDiv";
bgObj.style.cssText = "position:absolute;left:0px;top:0px;width:"+iWidth+"px;height:"+Math.max(document.body.clientHeight, iHeight)+"px;filter:Alpha(Opacity=80);opacity:0.3;background-color:#000000;z-index:100;";
document.body.appendChild(bgObj);
var msgObj=document.createElement("div");
msgObj.id = "MsgDiv";
msgObj.style.cssText = "position:absolute;font:11px '宋体';top:"+(iHeight-h)/2+"px;left:"+(iWidth-w)/2+"px;width:"+w+"px;height:"+h+"px;text-align:center;border:1px solid "+bordercolor+";background-color:"+bgcolor+";padding:1px;line-height:22px;z-index:102;";
document.body.appendChild(msgObj);
var table = document.createElement("table");
msgObj.appendChild(table);
table.style.cssText = "margin:0px;border:0px;padding:0px;";
table.cellSpacing = 0;
var tr = table.insertRow(-1);
var titleBar = tr.insertCell(-1);
titleBar.style.cssText = "width:100%;height:"+titleheight+"px;text-align:left;padding:3px;margin:0px;font:bold 13px '宋体';color:"+titlecolor+";border:1px solid " + bordercolor + ";cursor:move;background-color:" + titlebgcolor+";";
titleBar.style.paddingLeft = "10px";
titleBar.innerHTML = title;
var mask = document.createElement("iframe");
mask.src="javascript:false";
mask.scrolling="no";
mask.frameborder="0";
mask.style.cssText = "position:absolute;z-index:"+msgObj.style.zIndex-1+";top:"+msgObj.style.top+";left:"+msgObj.style.left+";width:"+msgObj.style.width+";height:"+msgObj.style.height+";";
mask.style.position="absolute";
document.body.appendChild(mask);
var moveX = 0;
var moveY = 0;
var moveTop = 0;
var moveLeft = 0;
var moveable = false;
addEvent(msgObj, "mousedown", mousedown);
addEvent(msgObj, "mouseup", mouseup);
addEvent(msgObj, "selectstart", function() {return false;});
addEvent(msgObj, "mousemove", mousemove);
var resizeEvent;
function mousedown() {
moveable = true;
resizeEvent=window.onresize;
window.onresize = function() {
bgObj.style.width = document.documentElement.clientWidth + "px";
bgObj.style.height = documes3Qnt.documentElement.clientHeight + "px";
}
if (getBrowser()=="IE") msgObj.setCapture();
var evt = getEvent();
moveX = evt.clientX;
moveY = evt.clientY;
moveTop = parseInt(msgObj.style.top);
moveLeft = parseInt(msgObj.style.left);
}
function mousemove() {
if (moveable) {
var evt = getEvent();
var x = moveLeft + evt.clientX - moveX;
var y = moveTop + evt.clientY - moveY;
msgObj.style.left = x + "px";
msgObj.style.top = y + "px";
mask.style.left = msgObj.style.left;
mask.style.top = msgObj.style.top;
}
}
function mouseup() {
if (moveable) {
moveX = 0;
moveY = 0;
moveTop = 0;
moveLeft = 0;
moveable = false;
window.onresize = resizeEvent;
if (getBrowser()=="IE") msgObj.releaseCapture();
}
}
var closeBtn = tr.insertCell(-1);
closeBtn.style.cssText = "cursor:pointer; padding:2px;background-color:" + titlebgcolor+";";
closeBtn.innerHTML = "<span style='font-size:15pt; color:"+titlecolor+";'>×</span>";
closeBtn.onclick = function(){
document.body.removeChild(bgObj);
document.body.removeChild(msgObj);
document.body.removeChild(mask);
}
var msgBox = table.insertRow(-1).insertCell(-1);
msgBox.id = "MsgBox";
msgBox.style.cssText = "font:10pt '宋体';";
msgBox.colSpan = 2;
msgBox.innerHTML = msg;
}
// 获得事件Event对象,用于兼容IE和FireFox
function getEvent() {
return window.event || arguments.callee.caller.arguments[0];
}
// 事件绑定
function addEvent(obj,eventTypeName, fn){
if(obj.addEventListener){
obj.addEventListener(eventTypeName,fn,true);
return true;
}else if(obj.attachEvent){
return obj.attachEvent("on"+eventTypeName,fn);
}else{
return false;
}
}
// 检测浏览器类型
function getBrowser() {
var b;
if ((navigator.userAgent.indexOf("MSIE") >= 0) && (navigator.userAgent.indexOf('Opera') < 0)) {
b = "IE";
}else if (navigator.userAgent.indexOf("Firefox") >= 0) {
b = "Firefox";
}else if (navigator.userAgent.indexOf("Opera") >= 0){
b = "Opera";
}else {
b = "Other";
}
return b;
}
</script>
</head>
<body>
<input type="button" value="点击试试" οnclick="alertWin('懒人建站','51xuediannao.com',300,200);" /><br/><br/>
<a href="javascript:alertWin('懒人建站','解放出你的部分写代码时间来思考更高层次的设计 51xuediannao.com',300,200);" _fcksavedurl="javascript:alertWin('懒人建站','懒人建站-解放出你的部分写代码时间来思考更高层次的设计-51xuediannao.com',300,200);">点击试试</a>
</body>
</html>

转载于:https://www.cnblogs.com/wangtiantian/p/5019306.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值