AlerBottom.js
4.68 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/*
*usage
//显示
$.AlerStatus({
status:'loading', //状态
msg:'上传中...', //文字0
duration:2000 //默认多少秒后隐藏,设null则一直不隐藏
})
//隐藏
$.AlerStatus({
type:'hide', //显示或隐藏,默认为show
time:3000 //3s后隐藏,默认为0
})
//loading
$.AlerBottom({
status:'loading', //加载中
duration:null,
callback:function(){
}
})
setTimeout(function(){
//加载完成
$.AlerBottom({
status:'loadingEnd',
time:1000,
duration:null,
callback:function(){
$.AlerBottom({
status:'success',
msg:'保存成功,正在为您跳转(5)',
duration:null
})
var leftTime=5;
setInterval(function(){
if(leftTime==0){
//window.location.href="http://www.baidu.com";
}else{
leftTime--
$('#AlerBottom .info').text('保存成功,正在为您跳转('+leftTime+')');
}
},1000)
}
})
},2000)
*/
(function (window, document) {
//选择器初始化
var $AlerBottom,$AlerBottomIn,$AlerBottomBg,$info,$status;
$(function () {
init(); //初始化
//选择器初始化
$AlerBottom=$('#AlerBottom');
$AlerBottomBg=$AlerBottom.find('.AlerBottomBg');
$AlerBottomIn=$AlerBottomBg.find('.AlerBottomBg-in');
$info=$AlerBottom.find('.info');
$status=$AlerBottom.find('.status');
})
function init() {
var _html = '<!--弹出框-->' +
'<div id="AlerBottom" style="display:none;">'+
'<div class="AlerBottomBg">'+
'<div class="AlerBottomBg-in"></div>'+
'</div>'+
'<span class="status"></span>'+
'<div class="info"></div>'+
'</div>'+
'<!--End 弹出框-->';
var AlerHTML = document.createElement('div');
AlerHTML.innerHTML = _html;
document.body.appendChild(AlerHTML);
}
//loading动画
var _loadingN=0;
var A;
var opts;
$.AlerBottom = function (options,callback) {
//默认参数
var defaults = {
type: 'show',
status: null,
msg: null,
time: 0,
duration: 2000
};
opts = $.extend({}, defaults, options);//赋值到全局变量opts
if (opts.type === 'show') {
$AlerBottom.show();
if(opts.msg){
$info.text(opts.msg);//如果有内容,则填充内容
$AlerBottom.css('padding','10px 0');
}else if(opts.status!=="loadingEnd"){
$info.empty();
$status.empty();
$AlerBottom.css('padding','3px 0');
}
if(opts.duration){
setTimeout(function(){
_hide();
},opts.duration);
}
switch(opts.status){
case 'loading':
if(opts.msg){
$status.html('<div class="la-ball-clip-rotate la-sm"><div></div></div>');
}
$AlerBottomBg.html('<div class="AlerBottomBg-in"></div>');
$AlerBottomIn=$AlerBottomBg.find('.AlerBottomBg-in');
$AlerBottom.attr('class','AlerBottom-loading');
AlerBottomBgLoading();
needCallback();
break;
case 'loadingEnd':
setTimeout(function(){
clearInterval(A);
$AlerBottomIn.width('100%');
needCallback();
},opts.time);
break;
case 'success':
setTimeout(function(){
$status.html('<div class="la-success la-sm"><div></div><div></div></div>');
$AlerBottom.css('-webkit-transition','none');
$AlerBottom.attr('class','AlerBottom-success');
needCallback();
},opts.time);
break;
case 'error':
setTimeout(function(){
$status.html('<div class="la-error la-sm"><div></div><div></div></div>');
$AlerBottom.css('-webkit-transition','none');
$AlerBottom.attr('class','AlerBottom-error');
needCallback();
},opts.time);
break;
}
} else if(opts.type === 'hide') {
_hide();
}
}
//执行自定义callback函数
function needCallback(){
if(opts.callback){
opts.callback();
}
}
function AlerBottomBgLoading(){
setTimeout(function(){
_loadingN=40;
$AlerBottomIn.css('width',_loadingN+"%");
A=setInterval(function(){
if(_loadingN<70){
_loadingN+=30;
$AlerBottomIn.css('width',_loadingN+"%");
}else if(_loadingN<90){
_loadingN+=20;
$AlerBottomIn.width(_loadingN+"%");
}else if(_loadingN<98){
_loadingN+=1;
$AlerBottomIn.width(_loadingN+"%");
}else{clearInterval(A);}
},500);
},800);
}
function _hide(){
setTimeout(function(){
$AlerBottom.css('-webkit-transform','translateY(-100%)');
setTimeout(function(){
$AlerBottom.hide().removeAttr('style class');
$AlerBottomIn.removeAttr('style').width(0);
},300);
},opts.time);
}
})(window, document);