alert 弹出框美化
2017-08-09 10:41
162 查看
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>弹出框美化</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<link href="css/style2.css" rel="stylesheet" />
<style>
#cmd_search{
width: 90%;
text-align: center;
color: #fff;
margin: 10px auto;
border-radius: 5px;
line-height: 30px;
cursor: pointer;
background: #4ab819;
}
</style>
</head>
<body>
<div id="cmd_search">查询</div>
</body>
<script src="js/jquery-2.1.1.min.js"></script>
<script src="js/ui.js"></script>
<script type="text/javascript">
$("#cmd_search").attr("onclick","mizhu.alert('温馨提示', '请选择有效时间!');");
</script>
</html>
style2.css
/*背景变灰*/
*{
font-family:"Helvetica Neue","Helvetica","Arial","sans-serif";}
.mask-layer {
position: fixed;
width: 100%;
height: 100%;
opacity: 0.5;
filter: alpha(opacity=50);
background-color:#f0f0f0;
z-index: 99998;
top: 0px;
left: 0px;
}
/*选择位置*/
.window-panel {
position: fixed;
z-index: 99999;
top: 50%;
left: 50%;
background-color: white;
border-radius: 4px;
box-shadow:3px 3px 5px 2px #b4b4b4;
}
/*标题设置*/
.window-panel .title-panel {
position: absolute;
height: 36px;
border-radius:5px;
}
.window-panel .title {
position: absolute;
height: 36px;
width: 100%;
text-align: center;
border-radius:5px 5px 0px 0px;
line-height: 36px;
background-color:#79A781;
border-bottom: 1px solid #79A781;
color:#fff;
z-index: 1;
}
.window-panel h3 {
font-size: 16px;
margin: 0;
}
/*设置确定按钮*/
.window-panel .btns {
text-align: right;
}
/*设置请设置时间的函数.window-panel .content 的类名*/
.window-panel .content {
padding: 30px 10px 0px 15px;
font-size: 16px;
min-height: 40px;
line-height: 22px;
color:#23527c;
}
/*设置确定按钮*/
.window-panel .w-btn {
display: inline-block;
width: 60px;
height: 26px;
line-height: 26px;
background-color: #fff;
color: #79a781;
cursor: pointer;
text-align: center;
border-radius: 5px;
text-decoration: none;
margin: 0 10px 0px 10px;
border:1px solid #79a781;
}
.window-panel .w-btn:hover {
color:#000;
background:#f8fffd;
}
.window-panel .w-btn:focus {
outline: 0 none;
}
ui.js
var mizhu = new function() {
this.width = 380;
this.height = 172;
this.close = function() {
$('.win iframe').fadeOut();
$('.win').fadeOut("fast");
setTimeout(function() {
$('.win iframe').remove();
$('.win').remove();
}, 200);
};
this.open = function(width, height, title, url, closed) {
this._close = function() {
this.close();
if($.isFunction(closed)) closed();
};
var html = '<div class="win"><div class="mask-layer"></div><div class="window-panel"><iframe class="title-panel" frameborder="0" marginheight="0" marginwidth="0" scrolling="no"></iframe><div class="title"><h3></h3></div><a
href="javascript:void(0)" onclick="mizhu._close();" class="close-btn" title="关闭">×</a><iframe class="body-panel" frameborder="0" marginheight="0" marginwidth="0" scrolling="auto" src=""></iframe></div></div>';
var alert_jq = $(html);
alert_jq.find(".window-panel").height(mizhu.height).width(mizhu.width).css("margin-left", -mizhu.width / 2).css("margin-top", -mizhu.height);
alert_jq.find(".title").find(":header").html(title);
alert_jq.find(".body-panel").height(height - 36).attr("src", url);
alert_jq.appendTo('body').fadeIn("fast");
$(".win .window-panel").focus();
};
function messageBox(html, title, message, type) {
var alert_jq = $(html);
if(type == "toast") {
alert_jq.find(".window-panel").width(message.length * 20).css("margin-left", -message.length * 20 / 2).css("margin-top", -mizhu.height / 2);
} else {
alert_jq.find(".window-panel").width(mizhu.width).css("margin-left", -mizhu.width / 2).css("margin-top", -mizhu.height / 2 - 36);
}
if(valempty(title)) {
alert_jq.find(".title").remove();
alert_jq.find(".window-panel .body-panel").css("border-radius", "4px");
} else {
alert_jq.find(".title").find(":header").html(title);
}
alert_jq.find(".content").html(message.replace('\r\n', '<br/>'));
alert_jq.appendTo('body').fadeIn("fast");
$(".win .w-btn:first").focus();
}
this.alert = function(title, message, ico) {
var alert_icon = "";
if(!valempty(ico)) {
alert_icon = '<p class="btns" style="margin-bottom:-15px;"><img width="70px" height="70px" src="images/' + ico + '.png"></p>';
}
var html = '<div class="win"><div class="mask-layer"></div><div class="window-panel"><iframe class="title-panel" frameborder="0" marginheight="0" marginwidth="0" scrolling="no"></iframe><div class="title"><h3></h3></div><div
class="body-panel">' + alert_icon + '<p class="content"></p><p class="btns"><button class="w-btn" tabindex="1" onclick="mizhu.close();">确定</button></p></div></div></div>';
messageBox(html, title, message);
}
this.toast = function(message, time) {
var html = '<div class="win"><div class="window-panel"><iframe class="title-panel" frameborder="0" marginheight="0" marginwidth="0" scrolling="no"></iframe><div class="body-panel toast-panel"><p class="content toast-content"></p></div></div></div>';
messageBox(html, "", message, "toast");
setTimeout(function() {
mizhu.close();
}, time || 3000);
}
};
function valempty(str) {
if(str == "null" || str == null || str == "" || str == "undefined" || str == undefined || str == 0) {
return true;
} else {
return false;
}
}
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>弹出框美化</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<link href="css/style2.css" rel="stylesheet" />
<style>
#cmd_search{
width: 90%;
text-align: center;
color: #fff;
margin: 10px auto;
border-radius: 5px;
line-height: 30px;
cursor: pointer;
background: #4ab819;
}
</style>
</head>
<body>
<div id="cmd_search">查询</div>
</body>
<script src="js/jquery-2.1.1.min.js"></script>
<script src="js/ui.js"></script>
<script type="text/javascript">
$("#cmd_search").attr("onclick","mizhu.alert('温馨提示', '请选择有效时间!');");
</script>
</html>
style2.css
/*背景变灰*/
*{
font-family:"Helvetica Neue","Helvetica","Arial","sans-serif";}
.mask-layer {
position: fixed;
width: 100%;
height: 100%;
opacity: 0.5;
filter: alpha(opacity=50);
background-color:#f0f0f0;
z-index: 99998;
top: 0px;
left: 0px;
}
/*选择位置*/
.window-panel {
position: fixed;
z-index: 99999;
top: 50%;
left: 50%;
background-color: white;
border-radius: 4px;
box-shadow:3px 3px 5px 2px #b4b4b4;
}
/*标题设置*/
.window-panel .title-panel {
position: absolute;
height: 36px;
border-radius:5px;
}
.window-panel .title {
position: absolute;
height: 36px;
width: 100%;
text-align: center;
border-radius:5px 5px 0px 0px;
line-height: 36px;
background-color:#79A781;
border-bottom: 1px solid #79A781;
color:#fff;
z-index: 1;
}
.window-panel h3 {
font-size: 16px;
margin: 0;
}
/*设置确定按钮*/
.window-panel .btns {
text-align: right;
}
/*设置请设置时间的函数.window-panel .content 的类名*/
.window-panel .content {
padding: 30px 10px 0px 15px;
font-size: 16px;
min-height: 40px;
line-height: 22px;
color:#23527c;
}
/*设置确定按钮*/
.window-panel .w-btn {
display: inline-block;
width: 60px;
height: 26px;
line-height: 26px;
background-color: #fff;
color: #79a781;
cursor: pointer;
text-align: center;
border-radius: 5px;
text-decoration: none;
margin: 0 10px 0px 10px;
border:1px solid #79a781;
}
.window-panel .w-btn:hover {
color:#000;
background:#f8fffd;
}
.window-panel .w-btn:focus {
outline: 0 none;
}
ui.js
var mizhu = new function() {
this.width = 380;
this.height = 172;
this.close = function() {
$('.win iframe').fadeOut();
$('.win').fadeOut("fast");
setTimeout(function() {
$('.win iframe').remove();
$('.win').remove();
}, 200);
};
this.open = function(width, height, title, url, closed) {
this._close = function() {
this.close();
if($.isFunction(closed)) closed();
};
var html = '<div class="win"><div class="mask-layer"></div><div class="window-panel"><iframe class="title-panel" frameborder="0" marginheight="0" marginwidth="0" scrolling="no"></iframe><div class="title"><h3></h3></div><a
href="javascript:void(0)" onclick="mizhu._close();" class="close-btn" title="关闭">×</a><iframe class="body-panel" frameborder="0" marginheight="0" marginwidth="0" scrolling="auto" src=""></iframe></div></div>';
var alert_jq = $(html);
alert_jq.find(".window-panel").height(mizhu.height).width(mizhu.width).css("margin-left", -mizhu.width / 2).css("margin-top", -mizhu.height);
alert_jq.find(".title").find(":header").html(title);
alert_jq.find(".body-panel").height(height - 36).attr("src", url);
alert_jq.appendTo('body').fadeIn("fast");
$(".win .window-panel").focus();
};
function messageBox(html, title, message, type) {
var alert_jq = $(html);
if(type == "toast") {
alert_jq.find(".window-panel").width(message.length * 20).css("margin-left", -message.length * 20 / 2).css("margin-top", -mizhu.height / 2);
} else {
alert_jq.find(".window-panel").width(mizhu.width).css("margin-left", -mizhu.width / 2).css("margin-top", -mizhu.height / 2 - 36);
}
if(valempty(title)) {
alert_jq.find(".title").remove();
alert_jq.find(".window-panel .body-panel").css("border-radius", "4px");
} else {
alert_jq.find(".title").find(":header").html(title);
}
alert_jq.find(".content").html(message.replace('\r\n', '<br/>'));
alert_jq.appendTo('body').fadeIn("fast");
$(".win .w-btn:first").focus();
}
this.alert = function(title, message, ico) {
var alert_icon = "";
if(!valempty(ico)) {
alert_icon = '<p class="btns" style="margin-bottom:-15px;"><img width="70px" height="70px" src="images/' + ico + '.png"></p>';
}
var html = '<div class="win"><div class="mask-layer"></div><div class="window-panel"><iframe class="title-panel" frameborder="0" marginheight="0" marginwidth="0" scrolling="no"></iframe><div class="title"><h3></h3></div><div
class="body-panel">' + alert_icon + '<p class="content"></p><p class="btns"><button class="w-btn" tabindex="1" onclick="mizhu.close();">确定</button></p></div></div></div>';
messageBox(html, title, message);
}
this.toast = function(message, time) {
var html = '<div class="win"><div class="window-panel"><iframe class="title-panel" frameborder="0" marginheight="0" marginwidth="0" scrolling="no"></iframe><div class="body-panel toast-panel"><p class="content toast-content"></p></div></div></div>';
messageBox(html, "", message, "toast");
setTimeout(function() {
mizhu.close();
}, time || 3000);
}
};
function valempty(str) {
if(str == "null" || str == null || str == "" || str == "undefined" || str == undefined || str == 0) {
return true;
} else {
return false;
}
}
相关文章推荐
- 弹出框美化 alert样式美化
- alert,confirm弹出窗样式美化
- Alert弹出窗口 美化
- 弹出框美化 alert样式美化
- js美化alert()弹出框
- Alert弹出窗口 美化体验版
- JavaScript弹出对话框的三种方式-alert()-confirm()-prompt()区别和联系
- Android提供常用的消息弹出框,Toast和Alert。
- JavaScript基础教程之alert弹出提示框实例
- Android6.0 申请SYSTEM_ALERT_WINDOW权限 没有弹出权限框
- Selenium2学习-040-JavaScript弹出框(alert、confirm、prompt)操作演示实例
- android webview js alert对话框 不能弹出 解决办法
- [CodeProject每日一荐] ASP.NET 仿MSN Messenger Alert的弹出窗口控件
- WKWebView捕获HTML弹出的Alert和Confirm
- C#实现在前端网页弹出警告对话框(alert)的方法
- ASP.net从服务器端向客户端弹出alert对话框,但不使页面变成白板
- React Native API模块之Alert弹出框详解及使用
- android webview js alert对话框 不能弹出 解决办法
- Flex4 加载模块Alert弹出框背景透明问题
- layer弹出层框架alert与msg详解