AlerStatus.js
1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
*usage
//显示
$.AlerStatus({
status:'loading', //状态
msg:'上传中...', //文字0
duration:2000 //默认多少秒后隐藏,设null则一直不隐藏
})
//隐藏
$.AlerStatus({
type:'hide', //显示或隐藏,默认为show
time:3000 //3s后隐藏,默认为0
})
*/
(function (window,document) {
$(function(){
init(); //初始化
})
function init() {
_html = ' <!--弹出框-->' +
'<div id="AlerStatus">' +
'<div class="AlerStatusBg"></div>' +
'<span class="status">' +
'<div class="img"><i></i></div>' +
'<div class="title"></div>' +
'</span>' +
'</div>' +
'<!--End 弹出框-->';
AlerHTML = document.createElement('div');
AlerHTML.innerHTML = _html;
document.body.appendChild(AlerHTML);
}
var opts;
$.AlerStatus = function (options) {
var defaults = {
type: 'show',
status: null,
msg: null,
time: 0,
duration: 2000
};
opts = $.extend({}, defaults, options);
if (opts.type == 'show') {
show_box(opts.status, opts.msg, opts.time, opts.duration);
} else {
hide_box(opts.time);
}
}
function show_box(status, msg, time, duration) {
setTimeout(function () {
$('#AlerStatus').show();
$('#AlerStatus .status').removeClass().addClass('status').addClass(status);
$('#AlerStatus .title').html(msg);
if (duration != null) {
hide_box(duration);
}
if (status == "loading") {
$('#AlerStatus .AlerStatusBg').show();
}
}, time);
}
function hide_box(time) {
setTimeout(function () {
$('#AlerStatus').fadeOut(300);
$('#AlerStatus .AlerStatusBg').hide();
}, time);
}
})(window,document);