alert效果
<!DOCTYPE html>
<head>
<meta charset="utf-8" />
<title>拉伸效果</title>
<style>
.mask50 {
width: 100%;
height: 100%;
position: fixed;
top: 0;
left: 0;
z-index: 10000;
background: rgba(0, 0, 0, .5);
overflow: auto;
} .js-alertFn {
width: 9.36rem;
position: absolute;
z-index: 11111;
background: #ffffff;
left: 50%;
top: 50%;
margin-left: -4.68rem;
-webkit-border-radius: .2rem;
-moz-border-radius: .2rem;
border-radius: .2rem;
overflow: hidden;
} .js-alertFn table {
border-collapse: collapse;
width: 100%;
border: .01rem solid #fff;
margin-left: -1px;
height: 100px
} .js-alertFn table tr td {
border-top: 1px solid #d4d4d4;
border-left: 1px solid #d4d4d4;
text-align: center;
padding: .2rem .4rem;
line-height: .8rem;
font-size: .5rem;
color: #333;
padding: 1rem .3rem;
} .js-alertFn table tr:last-child td {
height: 1rem;
width: 50%;
padding: .3rem !important;
}
</style>
</head>
<body>
<button onclick="selfAlert({})">确定</button>
</body>
</html>
<script type="text/javascript">
!function(a){function b(){ var b=g.getBoundingClientRect().width;a.rem=b/10.8,g.style.fontSize=a.rem+"px"}var g=a.document.documentElement,e;a.addEventListener("resize",function(){clearTimeout(e),e=setTimeout(b,300)},!1),a.addEventListener("pageshow",function(a){a.persisted&&(clearTimeout(e),e=setTimeout(b,300))},!1),b()}(window);
//弹出框方法
function alertFn(jn) {
this.json = {
msg : jn.msg || "系统错误",
btntxt : jn.btntxt || [ '确定', '取消' ],
type : jn.type || 2,
sure : jn.sure,
cancell : jn.cancell
}
this.init();
this.DOMlayout();
} alertFn.prototype.init = function() {
var mask = document.querySelector("#mask");
if (mask) {
mask.parentNode.removeChild(mask);
}
} alertFn.prototype.DOMlayout = function() {
var self = this;
var mask = document.createElement("div");
mask.className = "mask50";
mask.setAttribute("id", "mask")
if (this.json.type === 1) {
var alertBox = '<div class="js-alertFn"><table><tr>';
alertBox += '<td colspan="2">' + this.json.msg + '</td></tr>';
alertBox += '<tr><td id="cancel">' + this.json.btntxt[1]
+ '</td><td id="sure">' + this.json.btntxt[0] + '</td></tr>';
alertBox += '</table></div>';
} else {
var alertBox = '<div class="js-alertFn"><table><tr>';
alertBox += '<td>' + this.json.msg + '</td></tr>';
alertBox += '<tr><td id="sure">' + this.json.btntxt[0] + '</td></tr>';
alertBox += '</table></div>';
}
mask.innerHTML = alertBox;
document.body.appendChild(mask);
this.vm();
document.querySelector("#sure").onclick = function() {
self.sureFn()
}
var canBtn = document.querySelector("#cancel");
if (canBtn) {
canBtn.onclick = function() {
self.cancellFn()
}
}
} alertFn.prototype.vm = function() {
var box = document.querySelector(".js-alertFn");
var h = box.offsetHeight;
var mh = document.querySelector("#mask").offsetHeight;
box.style.top = (mh - h) / 2 + "px";
} alertFn.prototype.sureFn = function() {
this.init();
this.json.sure && this.json.sure();
} alertFn.prototype.cancellFn = function() {
this.init();
this.json.cancell && this.json.cancell();
} function selfAlert(json) {
return new alertFn(json);
}
</script>
alert效果的更多相关文章
- 实现js的类似alert效果的函数
这个简单的类似alert的函数,效果还行,至于css样式,那没的说了,笔者确实尽力了,如果读者觉得太烂,你可以随便改函数的样式的,反正,笔者觉得还可以,呵呵. <!DOCTYPE html PU ...
- alert 替代效果smoke.js
在一些表单等需要弹窗提醒的时候,每个浏览器都有一个alert(),comfirm()函数能弹出信息,但是浏览器的自带的这种效果样式不统一,而且都固定在页面顶部: smoke.js轻量级的JS插件,他标 ...
- 原生js实现自定义alert风格和实现
2018年6月29 最新更新 添加函数节流,解决多次点击问题,添加单例模式,提高代码性能. <!DOCTYPE html> <html lang="en"> ...
- 弹出框美化 alert样式美化
引用style.css和ui.js就可以直接用以下接口调用!(文末附完整代码) alert_带标题: mizhu.alert('alert_带标题', '这是alert效果'); alert_带图标: ...
- js的常用场景效果
转自https://www.cnblogs.com/tangdiao/p/9481681.html 1.checkbox的使用场景,学习之后就是购物车页面的自动计算的上手示例. 做成给checkbox ...
- 茗洋Easy UI 1.3.2 部分问题解决系列专题[Combo模糊匹配中文问题 修复]
本次给大家带来的EasyUI的我研究拓展的新特性 我使用的是 EasyUI 1.3.2版本的,项目是ASP.NET MVC3,但是本篇讲解用不上ASP.NET MVC,仅仅修改官方Demo你就知道怎 ...
- Easyui弹出窗体在iframe的父级页面显示
今天做EasyUI学习的预到了一个这样的问题:通过iframe加载的一个页面在调用$.messager.alert();这个方法后只能在iframe中显示alert效果而不是在全局的页面上显示这并不我 ...
- Combo模糊匹配中文问题
茗洋Easy UI 1.3.2 部分问题解决系列专题[Combo模糊匹配中文问题 修复] 本次给大家带来的EasyUI的我研究拓展的新特性 我使用的是 EasyUI 1.3.2版本的,项目是ASP. ...
- JQuery中根据表单元素动态拼接json 字符串
// <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.o ...
随机推荐
- ios开发证书
文章写得很透彻 https://segmentfault.com/a/1190000004144556?f=tt&hmsr=toutiao.io
- My 1st webUI try
1. Add three control to the UI: StartTime EndTime Weekdays: 2015-11-17 20:26:40 data-model: Html5在ht ...
- 摘抄的 JAVA JDOM 操作XML文件
JDOM修炼篇 用过XERCES的程序员都会感到,有时候用一句话就可以说清楚的事,当用XERCES的API来实现时,要三四行程序. 回页首 获得并安装JDOM 在 http://www.jdom. ...
- MS SQL 两种分页
------ row number ---------- ------ row number ---------- declare @pageSize int,@pageIndex int ; sel ...
- ANDROID L——Material Design详解(UI控件)
转载请注明本文出自大苞米的博客(http://blog.csdn.net/a396901990),谢谢支持! Android L: Google已经确认Android L就是Android Lolli ...
- Flex 布局2
Flex 布局2 你会看到,不管是什么布局,Flex往往都可以几行命令搞定. 我只列出代码,详细的语法解释请查阅<Flex布局教程:语法篇>.我的主要参考资料是Landon Sch ...
- Silverlight5 Tools安装失败及解决方案
Silverlight5 Tools在安装的时候往往会提示以下错误 解决办法:解压Silverlight5 Tools.exe,打开ParameterInfo.xml文件,将其中的1033全部替换为2 ...
- VS2013打开项目Web加载失败
今天打开一个好久没打开过的老项目,发现web加载失败,如图: 然后重新加载项目,提示: 一开始直接在网上找答案,结果看的答案都不靠谱,只好自己动手了, 先看了 这里面是基础配置:大概看过后,又去看了提 ...
- SSO
- gerrit session expired 怎么解决,搜索未果
gerrit session expired,怎么解决,搜索未果