message() 信息提示
程序员文章站
2023-11-07 18:25:22
//样式部分 .message { ......
//样式部分
.message {
position: fixed;top: -100px;width: 400px;left: 50%;margin-left: -200px;z-index: 1000;display: none;padding: 12px 0;text-align: center;color: #fff;background: #2196f3;
border-radius: 2px;-moz-box-sizing: border-box;-webkit-box-sizing: border-box;-o-box-sizing: border-box;-ms-box-sizing: border-box;box-sizing: border-box;-webkit-transition: all 0.46s ease;
-moz-transition: all 0.46s ease;-o-transition: all 0.46s ease;transition: all 0.46s ease;
}
.messageshow {top: 6px;z-index: 2000;}
//body部分
<div class="message"></div>
//js部分
function messageshow() {
var w = $('.message');
w.addclass('messageshow');
}
function messagehide() {
var w = $('.message');
w.removeclass('messageshow').removeclass('messageshownavfix');
w.html('');
}
function messageout() {
var w = $('.message');
w.css('display', 'none');
}
var t1, t2, t3;
function message(str) {
var w = $('.message');
cleartimeout(t1);
cleartimeout(t2);
cleartimeout(t3);
w.html(str);
w.css('display', 'block');
t1 = settimeout("messageshow()", 80);
t2 = settimeout("messagehide()", 2500);
t3 = settimeout("messageout()", 3000);
}
//应用部分,如:
$('.btn').click(function(){
message("手机号不能为空,请输入手机号");
return;
});