现在的位置: 首页 > 综合 > 正文

可以拖动的居中弹出层带遮罩效果

2018年06月10日 ⁄ 综合 ⁄ 共 5374字 ⁄ 字号 评论关闭

 原链接:http://www.51xuediannao.com/JS/texiao/juzhongtanchu.html

 

<!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="点击试试" onclick="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>

 

 

 

 

 

 

 

 

 

<!--下面只是说明与程序代码无关-->
<div style="width:95%; height:auto; display:block; margin:0 auto; margin-top:30px; font-size:10pt; line-height:150%;">
<span>本代码由<a href="http://www.51xuediannao.com" style="color:#F00;">懒人建站网 收集整理 我要学电脑.COM →51xuediannao.com</a> </span><br>
<a href="http://www.51xuediannao.com">懒人建站 http://www.51xuediannao.com</a><br/>
<span>我们为您提供-
<a href="http://www.51xuediannao.com/html+css/">HTML+CSS模板</a>,
<a href="http://www.51xuediannao.com/js/">JS代码</a>,
<a href="http://www.51xuediannao.com/JS/texiao/">网页特效</a>,
<a href="http://www.51xuediannao.com/JS/nav/">导航菜单</a>,
<a href="http://www.51xuediannao.com/JS/Slide/">焦点幻灯片<a>,
<a href="http://www.51xuediannao.com/JS/show/">网页欣赏</a>和
<a href="http://www.51xuediannao.com/JS/jiqiao/css/">CSS技巧</a>;</span>
<span>懒人建站只收录实用和能提高用户体验的代码</span>
<span>我们只想解放出你的部分写代码时间来思考更高层次的设计,而不是要你懒惰、拼凑。</span>
</div>

抱歉!评论已关闭.