Js弹出层,弹出框代码
<!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=utf-8" />
<title>弹出层效果</title>
<style type="text/css">
html, body {height:100%;}
body, h2, p {margin:0px;padding:0px; font-size:12px;}
body {font-size:12px; text-align:center; }
.alert_backg {width:100%;height:100%;top:0px;left:0px;position:absolute;background:#000;opacity:0;filter:alpha(opacity:0)}
.alert_frame {width:340px;height:120px;top:50%;left:50%;position:absolute;display:inline;margin:-60px 0 0 -170px;opacity:0;filter:alpha(opacity:0)}
.alert_frame .top_l {width:5px;height:5px;float:left;overflow:hidden;background:url(/jscss/demoimg/201109/corner.png) no-repeat;}
.alert_frame .top_c {width:330px;height:5px;float:left;overflow:hidden;background:url(/jscss/demoimg/201109/wraplayer.png) repeat-x;}
.alert_frame .top_r {width:5px;height:5px;float:left;overflow:hidden;background:url(/jscss/demoimg/201109/corner.png) no-repeat -5px 0;}
.alert_frame .con {width:100%;height:110px;float:left;overflow:hidden;}
.alert_frame .con_l {width:5px;height:100%;float:left;overflow:hidden;background:url(/jscss/demoimg/201109/wraplayer.png) repeat-y;}
.alert_frame .con_c {width:330px;height:100%;float:left;overflow:hidden;background:#fff;}
.alert_frame .con_r {width:5px;height:100%;float:left;overflow:hidden;background:url(/jscss/demoimg/201109/wraplayer.png) repeat-y;}
.alert_frame .bot_l {width:5px;height:5px;float:left;overflow:hidden;background:url(/jscss/demoimg/201109/corner.png) no-repeat 0 -5px;}
.alert_frame .bot_c {width:330px;height:5px;float:left;overflow:hidden;background:url(/jscss/demoimg/201109/wraplayer.png) repeat-x;}
.alert_frame .bot_r {width:5px;height:5px;float:left;overflow:hidden;background:url(/jscss/demoimg/201109/corner.png) no-repeat -5px -5px;}
.alert_frame .alert_tit {width:328px;height:27px;float:left;color:#000;line-height:27px;border:1px solid #fff;background:url(/jscss/demoimg/201109/alert_tit_bg.jpg) repeat-x;}
.alert_frame .alert_tit h2 {float:left;text-indent:10px;font-size:14px;font-weight:bold;font-family:"\u5FAE\u8F6F\u96C5\u9ED1";}
.alert_frame .alert_tit em {width:8px;height:7px;overflow:hidden;float:right;cursor:pointer;background:url(/jscss/demoimg/201109/gnbimgs.gif) no-repeat;display:inline;margin:10px 10px 0 0;}
.alert_frame .alert_tit em.hove {background:url(/jscss/demoimg/201109/gnbimgs.gif) no-repeat -8px 0;}
.alert_frame .alert_con {width:330px;height:81px;float:left;border-top:1px solid #e5e5e5;}
.size {width:100%;height:45px;text-align:center;line-height:45px;color:#000;}
.but {width:100%;height:22px;text-align:center;line-height:22px;}
.button {width:55px;height:22px;text-align:center;line-height:22px;color:#fff;background:url(/jscss/demoimg/201109/but.jpg) no-repeat;border:none;display:inline;margin:0 8px;cursor:pointer;}
.title {width:800px;height:35px;color:#fff;line-height:35px;font-family:Verdana;font-weight:bold;text-align:left;margin:20px auto 0 auto;font-size:24px;}
.table {width:800px;height:auto;overflow:hidden;margin:0 auto 20px auto;font-size:12px;border-top:1px solid #ddd;border-left:1px solid #ddd;background:#fff;}
.table ul {margin:0px;padding:0px;float:left;list-style-type:none;}
.table li {width:159px;height:30px;float:left;color:#3e3e3e;text-indent:10px;text-align:left;line-height:30px;font-family:Verdana,"微软雅黑"; border-right:1px solid #ddd;border-bottom:1px solid #ddd;}
.table li.td {color:#fff;font-size:14px;font-family:"微软雅黑";font-weight:bold;background:#424242;}
.table li.tit {width:479px;}
.table .tr {width:800px;height:30px;float:left;text-indent:10px;text-align:left;line-height:30px;font-size:14px;font-family:Verdana;border-right:1px solid #ddd;border-bottom:1px solid #ddd;}
.table .tr a {color:#ff6600;text-decoration:none;}
.table .tr a:hover {text-decoration:underline;}
</style>
<script type="text/javascript">
function $(id){
return typeof id === "string" ? document.getElementById(id) : id;
}
function $$(oParent, elem){
return (oParent || document).getElementsByTagName(elem);
}
function $$$(oParent, sClass){
var aElem = $$(oParent, '*');
var aClass = [];
var i = 0;
for(i=0;i<aElem.length;i++)if(aElem[i].className == sClass)aClass.push(aElem[i]);
return aClass;
}
function Alert(){
this.initialize.apply(this, arguments);
}
Object.extend = function(destination, source){
for (var property in source) {
destination[property] = source[property];
}
return destination;
};
Alert.prototype = {
initialize : function(obj, frame, onEnd){
if($(obj)){
var _this = this;
this.obj = $(obj);
this.frame = frame;
this.oEve(onEnd);
this.oTitle = this.onEnd.title;
this.oContent = this.onEnd.content;
this.iWidth = this.onEnd.width;
this.iHeight = this.onEnd.height;
this.iTop = this.onEnd.top;
this.iLeft = this.onEnd.left;
this.iFixed = this.onEnd.fixed;
this.iClose = this.onEnd.close;
this.obj.onclick = function(){_this.create(),_this.backg();};
window.onresize = function(){_this.backg();};
}
},
create : function(){
this.oDiv = document.createElement('div');
this.oAlert_backg = document.createElement('div');
this.oAlert_frame = document.createElement('div');
this.oTop_l = document.createElement('div');
this.oTop_c = document.createElement('div');
this.oTop_r = document.createElement('div');
this.oCon = document.createElement('div');
this.oCon_l = document.createElement('div');
this.oCon_c = document.createElement('div');
this.oCon_r = document.createElement('div');
this.oBot_l = document.createElement('div');
this.oBot_c = document.createElement('div');
this.oBot_r = document.createElement('div');
this.oDiv.id = this.frame;
this.oAlert_backg.className = 'alert_backg';
this.oAlert_frame.className = 'alert_frame';
this.oTop_l.className = 'top_l';
this.oTop_c.className = 'top_c';
this.oTop_r.className = 'top_r';
this.oCon.className = 'con';
this.oCon_l.className = 'con_l';
this.oCon_c.className = 'con_c';
this.oCon_r.className = 'con_r';
this.oBot_l.className = 'bot_l';
this.oBot_c.className = 'bot_c';
this.oBot_r.className = 'bot_r';
document.body.appendChild(this.oDiv);
this.box = $(this.frame);
this.box.appendChild(this.oAlert_backg);
this.box.appendChild(this.oAlert_frame);
this.oFra = $$$(this.box, 'alert_frame')[0];
this.oFra.appendChild(this.oTop_l);
this.oFra.appendChild(this.oTop_c);
this.oFra.appendChild(this.oTop_r);
this.oFra.appendChild(this.oCon);
this.oFra.appendChild(this.oBot_l);
this.oFra.appendChild(this.oBot_c);
this.oFra.appendChild(this.oBot_r);
this.oCone = $$$(this.box, 'con')[0];
this.oCone.appendChild(this.oCon_l);
this.oCone.appendChild(this.oCon_c);
this.oCone.appendChild(this.oCon_r);
this.tit = $(this.frame);
this.con = $$$(this.tit, 'con_c')[0];
this.oAlert_tit = document.createElement('div');
this.oAlert_con = document.createElement('div');
this.oH2 = document.createElement('h2');
this.oAlert_tit.className = 'alert_tit';
this.oAlert_con.className = 'alert_con';
if(this.oTitle != ""){
this.con.appendChild(this.oAlert_tit);
this.con.appendChild(this.oAlert_con);
this.oAlert_tit = $$$(this.tit, 'alert_tit')[0];
this.oH2.innerHTML = this.oTitle;
this.oAlert_tit.appendChild(this.oH2);
}
this.content();
this.width();
this.height();
this.top();
this.left();
this.fixed();
this.close();
this.Top = this.oFra.offsetTop;
this.oFra.style.top = (this.Top - 40) +'px';
this.oFra.style.marginTop = 0;
this.sMove(this.oFra, {top:this.Top, opacity:100});
this.sMove(this.oBackg, {opacity:50});
},
oEve: function(onEnd){
this.onEnd = {};
Object.extend(this.onEnd, onEnd || {});
},
content : function(){
this.conent = $$$(this.tit, 'alert_con')[0];
this.conent == undefined ? this.con.innerHTML = this.oContent : this.conent.innerHTML = this.oContent;
this.oButton = $$(this.tit, 'button');
var i = 0;
var _this = this;
for(i=0;i<this.oButton.length;i++)this.oButton[i].onclick = function(){_this.em.onclick()};
},
width : function(){
this.oBackg = $$$(this.tit, 'alert_backg')[0];
this.oFrame = $$$(this.tit, 'alert_frame')[0];
this.oCon = $$$(this.oFrame, 'con')[0];
this.oTop_c = $$$(this.oFrame, 'top_c')[0];
this.oCon_c = $$$(this.oFrame, 'con_c')[0];
this.oBot_c = $$$(this.oFrame, 'bot_c')[0];
this.oAlert_tit = $$$(this.oFrame, 'alert_tit')[0];
this.oAlert_con = $$$(this.oFrame, 'alert_con')[0];
if(this.iWidth != ""){
this.oFrame.style.width = parseInt(this.iWidth) +'px';
this.oFrame.style.marginLeft = -parseInt(this.iWidth) / 2 +'px';
this.oTop_c.style.width = parseInt(this.iWidth) - 10 +'px';
this.oCon_c.style.width = parseInt(this.iWidth) - 10 +'px';
this.oBot_c.style.width = parseInt(this.iWidth) - 10 +'px';
this.oAlert_tit.style.width = parseInt(this.iWidth) - 12 +'px';
this.oAlert_con.style.width = parseInt(this.iWidth) - 10 +'px';
}
},
height : function(){
if(this.iHeight != ""){
this.oFrame.style.height = parseInt(this.iHeight) +'px';
this.oFrame.style.marginTop = -parseInt(this.iHeight) / 2 +'px';
this.oCon.style.height = parseInt(this.iHeight) - 10 +'px';
this.oAlert_con.style.height = parseInt(this.iHeight) - 40 +'px';
}
},
top : function(){
if(this.iTop != "")this.oFrame.style.top = parseInt(this.iTop) +'px',this.oFrame.style.marginTop = 0;
},
left : function(){
if(this.iLeft != "")this.oFrame.style.left = parseInt(this.iLeft) +'px',this.oFrame.style.marginLeft = 0;
},
backg : function(){
this.oScrollHeight = document.documentElement.scrollHeight || document.body.scrollHeight;
this.oScrollWidth = document.documentElement.scrollWidth || document.body.scrollWidth;
this.oBackg.style.width = document.documentElement.clientWidth + (this.oScrollWidth - document.documentElement.clientWidth) +'px'
this.oBackg.style.height = document.documentElement.clientHeight + (this.oScrollHeight - document.documentElement.clientHeight) +'px'
},
fixed : function(){
if(this.iFixed == "fixed"){
var _this = this;
this.oFrame.style.position = 'fixed';
this.oAlert_tit.style.cursor = 'move';
this.oAlert_tit.onmousedown = function(e){
var _thisE = this;
this.oEvent = e || event;
this.X = this.oEvent.clientX - _this.oFrame.offsetLeft;
this.Y = this.oEvent.clientY - _this.oFrame.offsetTop;
document.onmousemove = function(e){
this.oEvent = e || event;
this.L = this.oEvent.clientX - _thisE.X;
this.T = this.oEvent.clientY - _thisE.Y;
if(this.L < 0){
this.L = 0;
}else if(this.L > document.documentElement.clientWidth - _this.oFrame.offsetWidth){
this.L = document.documentElement.clientWidth - _this.oFrame.offsetWidth
}
if(this.T < 0){
this.T = 0;
}else if(this.T > document.documentElement.clientHeight - _this.oFrame.offsetHeight){
this.T = document.documentElement.clientHeight - _this.oFrame.offsetHeight;
}
_this.oFrame.style.left = this.L + 'px';
_this.oFrame.style.top = this.T + 'px';
_this.oFrame.style.margin = 0;
return false;
}
document.onmouseup = function(){
document.onmouseup = null;
document.onmousemove = null;
};
return false;
};
if(this.oFrame){
if(!-[1,] && !window.XMLHttpRequest){
document.documentElement.style.textOverflow = "ellipsis";
this.oFrame.style.position = "absolute";
this.oFrame.style.setExpression("top", "eval(documentElement.scrollTop + " + this.oFrame.offsetTop + ') + "px"');
}
}
}
},
close : function(){
if(this.iClose == "close" && this.oTitle != ""){
var _this = this;
this.clos = $$$(this.tit, 'alert_tit')[0];
var oEm = document.createElement('em');
this.clos.appendChild(oEm);
this.em = $$(this.tit, 'em')[0];
this.em.onmouseover = function(){_this.em.className = 'hove';};
this.em.onmouseout = function(){_this.em.className = '';};
this.em.onclick = function(){
_this.sMove(_this.oFra, {top:(_this.Top - 40), opacity:0},function(){
document.body.removeChild(_this.em.parentNode.parentNode.parentNode.parentNode.parentNode);
});
_this.sMove(_this.oBackg, {opacity:0});
}
}
},
getStyle : function(obj, attr)
{
return obj.currentStyle?obj.currentStyle[attr]:getComputedStyle(obj, false)[attr];
},
sMove : function(obj, json, onEnd){
var _this = this;
clearInterval(obj.timer);
obj.timer = setInterval(function(){
_this.dMove(obj, json, onEnd);
},30);
},
dMove : function(obj, json, onEnd){
this.attr = '';
this.bStop = true;
for(this.attr in json){
this.iCur = 0;
this.attr == 'opacity' ? this.iCur = parseInt(parseFloat(this.getStyle(obj, this.attr))*100) : this.iCur = parseInt(this.getStyle(obj, this.attr));
this.iSpeed = (json[this.attr] - this.iCur) / 7;
this.iSpeed = this.iSpeed > 0 ? Math.ceil(this.iSpeed) : Math.floor(this.iSpeed);
if(json[this.attr] != this.iCur)this.bStop = false;
if(this.attr == 'opacity'){
obj.style.filter = 'alpha(opacity:' + (this.iCur + this.iSpeed) +')';
obj.style.opacity = (this.iCur + this.iSpeed ) / 100;
}else{
obj.style[this.attr] = this.iCur + this.iSpeed + 'px';
}
}
if(this.bStop){
clearInterval(obj.timer);
if(onEnd)onEnd();
}
}
};
window.onload = function(){
new Alert('but', 'box', {
title : '提示内容',
content : '<div class="size">确定不在关注新浪微博?</div><div class="but"><button class="button">确定</button><button class="button">取消</button></div>',
width : '',
height : '',
top : '',
left : '',
fixed : '',
close : 'close'
});
};
</script>
</head>
<body style="height:950px;">
<div class="title">API</div>
<div class="table">
<ul>
<li class="td">属性</li>
<li class="td">默认值</li>
<li class="tit td">说明</li>
<li>ButId</li>
<li>but</li>
<li class="tit">点击按钮Id(必选)</li>
<li>ElementId</li>
<li>box</li>
<li class="tit">弹出层Id(必选)</li>
<li>title</li>
<li>提示信息</li>
<li class="tit">提示层标题(可选)</li>
<li>content</li>
<li>自行编辑</li>
<li class="tit">提示层内容(可选)</li>
<li>width</li>
<li>340px</li>
<li class="tit">提示层宽度(可选)</li>
<li>height</li>
<li>120px</li>
<li class="tit">提示层高度(可选)</li>
<li>top</li>
<li>绝对居中</li>
<li class="tit">提示层上间距(可选)</li>
<li>left</li>
<li>绝对居中</li>
<li class="tit">提示层上间距(可选)</li>
<li>fixed</li>
<li>相对定位</li>
<li class="tit">跟谁滚动条绝对定位/是否拖拽(fixed:'fixed')(可选)</li>
<li>close</li>
<li>close</li>
<li class="tit">是否显示关闭按钮(close:'close')(可选)</li>
</ul>
<div class="tr"><a href="javascript:;" id="but">Examples</a></div>
</div>
</body>
</html>
Js弹出层,弹出框代码的更多相关文章
- 基于jQuery弹出层图片动画查看代码
分享一款基于jQuery弹出层图片动画查看代码是一款鼠标单击文字或图片内容放大显示且含圆角投影效果.效果图如下: 在线预览 源码下载 实现的代码. html代码: <div class=&q ...
- js div浮动层拖拽效果代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- bootstrap弹出层嵌套弹出层后文本框不能获得焦点输入
如图上 我从页面打开一个bootstrap弹出层 然后又在 bootstrap弹出层的基础上打开一个layui的弹出层 打开后发现文本域获取不到焦点不能输入内容 而该弹出层显示的层级体现出来了 按钮 ...
- 带emoji表情弹出层的评论框,semantic+emoji picker,java.sql.SQLException: Incorrect string value: '\xF0\x9F..'
在自己做一个项目玩时,在做评论的时候. 选中了semantic.js原型,这个在国内用的不是很多,但是在github上star数量很高,想当初我想找一个js框架是就在上面找的. semantic中文网 ...
- element-ui 弹出组件的遮罩层在弹出层dialog模态框的上面
造成的原因: 因为dialog的组件外层div设置了 position:absolute: 属性所以导致遮罩层会在最上面. 解决方法: 在属性内加上这段代码 :append-to-body=&quo ...
- layer.open获取弹出层的input框的值
使用top.$('#txtReason').val();获取值: //不通过 function unAuditData(id) { parent.layer.open({ type: , title: ...
- html 通用 遮罩弹出层 弹出后 支持跳转页面
//showMessage 提示的内容默认为空必填 buttonText:按钮显示的内容默认为"确定" 传入 "" 为默认 url:跳转链接 传入"& ...
- div滚动条弹出层效果 (所需要的css文件和js文件,都已经上传到文件里面了progressbar.rar)
<%--总的弹出层--%> <div class="tcck" id="joinclub" style="display:none& ...
- js进阶 11-20 弹出层如何制作
js进阶 11-20 弹出层如何制作 一.总结 一句话总结:其实就是一个div,控制显示和隐藏即可.设置成绝对定位更好,就可以控制弹出层出现的位置.关闭的画质需要将display重新设置为none就好 ...
- zDiaLog弹出层
zDiaLog弹出层 立即下载 插件描述:zDiaLog弹出层 弹出框: 代替window.open.window.alert.window.confirm:提供良好的用户体验: 水晶质感,设计细腻 ...
随机推荐
- 配置apache以fastcgi运行php
apache默认是用自带的mod_php模块运行php,现在我们介绍使用fastcgi来执行php脚本.先说下fastcgi的优点: Fastcgi的优点: 从稳定性上看, fastcgi是以独立的进 ...
- 嵌入式 十个最值得阅读学习的C开源项目代码
开源世界有许多优秀的开源项目,我选取其中十个最优秀的.最轻量级的C语言的项目,希望可以为C语言开发人员提供参考. 十个最值得阅读学习的C开源项目代码 1. Webbench 2. Tinyhttpd ...
- cocos2dx lua中继承与覆盖C++方法
cocos2dx的extern.lua中的class方法为lua扩展了面向对象的功能,这使我们在开发中可以方便的继承原生类 但是用function返回对象的方法来继承C++类是没有super字段的,这 ...
- web-ylbtech-数据库备份-数据库设计
ylbtech-DatabaseDesgin:web-ylbtech-数据库备份-数据库设计 DatabaseName:ylbtech Model:备份 Type:数据库备份设计 Url: 1.A,数 ...
- 解决 winform 界面对不齐 z
一个winform的程序,本机上界面对得很齐,到一到客户的机器上就惨不忍睹,一番研究后搞定: 1. AutoScaleMode = None 2. BackgroundImageLayout = No ...
- 插件五之滚动条jquery.slimscroll.js
前言 slimscroll.js用于模拟传统的浏览器滚动条(竖向),原理为原内容内置于一个仅可视区域显示层,使用2个div层用于模拟滚动条和滚动条背景轨道监听滚动条div高度变化来控制内容层位置(猜测 ...
- ASP.NET MVC3细嚼慢咽---(1)网站创建与发布
这一节我们演示下怎样使用VS2010创建与发布MVC3建立的网站.使用VS2010创建MVC3.0网站,需要下载MVC3.0的安装包,这个大家可以去网络上下载. 1.项目创建 ...
- bzoj 1492 [NOI2007]货币兑换Cash(斜率dp+cdq分治)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1492 [题意] 有AB两种货币,每天可以可以付IPi元,买到A券和B券,且A:B= ...
- servicestack操作redis
tatic void Main(string[] args) { );//redis服务IP和端口 #region =insert= var storeMembers = new List<st ...
- js中location.search、split()HTML5中localStorage
1. location.search在客户端获取Url参数的方法 location.search是从当前URL的?号开始的字符串 如:http://www.baidu.com/s?wd=baidu&a ...