alert 弹出框美化

<!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)" οnclick="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" οnclick="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;
}
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值