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 ...
随机推荐
- windows下Bat命令学习
一.基础语法:1.批处理文件是一个“.bat”结尾的文本文件,这个文件的每一行都是一条DOS命令.可以使用任何文本文件编辑工具创建和修改.2.批处理是一种简单的程序,可以用 if 和 goto 来控制 ...
- js瀑布流(定位法)
1.首先,自己写好图片路径,引入jquery <!DOCTYPE html> <html> <head> <meta charset="utf-8& ...
- simple mail example for smtp debug
vim /etc/mail.rc head /etc/rc.local | mail -s "test_email" pyz_sub1@mailtest.com
- C# async and await
C# 5.0中引入了async 和 await.这两个关键字可以让你更方便的写出异步代码. 看个例子: public class MyClass { public MyClass() { Displa ...
- PhpStorm 4.0 & 5.0 部署本地Web应用 (转)
1.创建新的项目(project),创建完成之后单击工具栏的应用运行/调试(Select Run/Debug Configuration)的下拉菜单弹出 Edit Cofigurations选项,单击 ...
- ThroughRain第一次冲刺(每天更新)
第一次冲刺时间: 11月14-11月23 第一次冲刺目标及分配: 1.注册登录界面 认领:王大华 2.界面跳转 认领:梁仕标 3.点餐界面 ...
- Eclipse版本android 65535解决方案(原理等同android studio现在的分包方式)
由于工作的需要看了下Eclipse下android65535的解决方案,查了好多文档,真心的发自内心的说一句请不要再拷贝别人的博客了,害人,真害人. 接下来我说下我的实现方式,首先说下65535的最可 ...
- CopyFile类通过调用这个类的delete(String filePath)方法可以组合成一个Cut类
package folderoperation; import java.io.File;/** * 注意它会删除文件,文件夹以及文件夹下的所有内容(根据指定的地址) * @author Dawn * ...
- spring MVC和hibernate的结合
我们在没有用注解写spring配置文件的时候:会在spring配置文件中定义Dao层的bean,这样我们在service层中,写setDao方法,就可以直接通过接口调用Dao层. ...
- Best Part