封装弹窗组件
来源:互联网 发布:p2p网管软件 编辑:程序博客网 时间:2024/05/16 18:10
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" /> <title>封装弹窗组件</title> <style type="text/css" media="screen"> .login{ border:1px solid #000; position:absolute; z-index:2; } .title{ height:50px; background:#ccc; font-size:24px; line-height:50px; } .title .close{ float:right; } #mask{ position: absolute; background:black; filter:alpha(opacity=50); opacity:0.5; top:0; left:0; z-index:1; } </style></head><body> <input type="button" name="" value='1'> <input type="button" name="" value='2'> <input type="button" name="" value='3'> <script type="text/javascript"> window.onload = function() { var aInput = document.getElementsByTagName('input'); aInput[0].onclick = function() { var d1 = new Dialog(); d1.init({ //配置参数,有配置走配置,没配置走默认 iNow:0, title:'登录' }); } aInput[1].onclick = function() { var d1 = new Dialog(); d1.init({ //配置参数,有配置走配置,没配置走默认 iNow:1, width:200, height:400, background:'red', dir:'rightBottom', title:'公告' }); } aInput[2].onclick = function() { var d1 = new Dialog(); d1.init({ //配置参数,有配置走配置,没配置走默认 iNow:2, mask:true }); } } function Dialog() { var obj = null; this.settings = { //默认 width:300, height:300, background:'#fff', dir:'center', mask:false, title:'' } } Dialog.prototype.json = {}; Dialog.prototype.init = function(opt) { extend(this.settings,opt); if (this.json[opt.iNow] == undefined) { this.json[opt.iNow] = true; } if (this.json[opt.iNow]) { this.create(); this.close(); if (this.settings.mask) { this.createMask(); } this.json[opt.iNow] = false; } } Dialog.prototype.create = function() { this.obj = document.createElement('div'); this.obj.className = 'login'; this.obj.innerHTML = `<div class='title'><span>${this.settings.title}</span><span class='close'>关闭</span></div>`; document.body.appendChild(this.obj); this.setData(); } Dialog.prototype.setData = function() { this.obj.style.width = this.settings.width + 'px'; this.obj.style.height = this.settings.height + 'px'; this.obj.style.background = this.settings.background; if (this.settings.dir == 'center') { this.obj.style.left = (viewWidth() - this.obj.offsetWidth)/2 + 'px'; this.obj.style.top = (viewHeight() - this.obj.offsetHeight)/2 + 'px'; } else if (this.settings.dir == 'rightBottom') { this.obj.style.left = (viewWidth() - this.obj.offsetWidth) + 'px'; this.obj.style.top = (viewHeight() - this.obj.offsetHeight) + 'px'; } } Dialog.prototype.close = function() { var oClose = this.obj.getElementsByTagName('span')[1]; var _this = this; oClose.onclick = function() { if (_this.settings.mask) { document.body.removeChild(_this.oMask); } document.body.removeChild(_this.obj); _this.json[_this.settings.iNow] = true; } } Dialog.prototype.createMask = function() { var oMask = document.createElement('div'); oMask.id = 'mask'; this.oMask = oMask; oMask.style.width = viewWidth() + 'px'; oMask.style.height = viewHeight() + 'px'; document.body.appendChild(oMask) } function extend(obj1,obj2) { for (var attr in obj2) { if (obj2.hasOwnProperty(attr)) { obj1[attr] = obj2[attr]; } } } function viewWidth() { return document.documentElement.clientWidth; } function viewHeight() { return document.documentElement.clientHeight; } </script></body></html>
0 0
- 封装弹窗组件
- 封装弹框
- 【转载】Asp.NET大文件上传组件开发总结(四)---封送数据给Asp.NET页面
- Proe5 .0wildfire免安装版去掉进入时的安装弹框脚本错误提示
- 第三封
- 封文件夹
- 封ip
- 局域网封QQ
- 我国第一封电子邮件
- 一封情书
- 封腾讯(转)
- GOOGLE被封了?
- 一封情书
- 一封情书
- 一封拒绝信
- 封心念晨!
- 中国第一封email
- xmlhttp封裝了
- mybatis框架(二)——核心组件及其作用
- jsp内置对象(隐含对象)
- 被误解的 MVC 和被神化的 MVVM
- 转发和重定向的区别(简单解释)
- RGB对照表
- 封装弹窗组件
- spring boot 使用自定义配置
- JBoss/Wildfly 配置SQLserver服务器
- 【2-5】Python基础——dict和set
- uva 12504 Updating a Dictionary(更新字典)
- 进程间通信之WM_COPYDATA的基本实现
- Java泛型:通配符
- 动态规划:最长上升子序列之基础(经典算法 n^2)
- ext4 设备文件处理