-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzw_loading.js
More file actions
89 lines (86 loc) · 2.48 KB
/
Copy pathzw_loading.js
File metadata and controls
89 lines (86 loc) · 2.48 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
/*
loading提示框插件:
版本:v1.0
调用方式:
1、zwLoading({content:"请耐心等待",mark:"slideUp",time:10,overlay:true,w:200,h:60});,
2、new zw_loading({content:"请耐心等待,正在为您努力加载中..."});
参数:
content:必选项,提示内容
mark:可选项,提示进出时的效果
time:可选项,提示消失时间
overlay:可选项,是否添加遮罩层,默认为否
w:可选项,提示宽度。默认<=320px
h:可选项,提示高度。默认为auto
*/
var zw_loading = function(options){
var opts = $.extend({},options);
this.init(opts);
};
zw_loading.prototype = {
init : function(opts){
var $dom = this.template(opts);
this._position($dom);
this._event(opts,$dom);
this._timer(opts,$dom);
},
template : function(opts){
var $loading = $("#zwui-loading");
var html = "";
var overlay = "";
// 有层存在时,更改文字,没有层存在时,弹出层。防止上一个层没关闭用户就点击了下一次操作,同时弹出一个以上的层
if($loading.length == 0){
html = "<div id='zwui-loading'>"
+"<div id='zwui-loading-cnt'>"+opts.content+"</div>"
+"</div>";
$("body").append(html);
}else{
$loading.find("#zwui-loading-cnt").html(opts.content);
}
$loading = $("#zwui-loading");
// 是否添加阴影层
if(opts.overlay){
overlay = "<div id='zwui-loading-overlay'></div>";
$loading.append(overlay);
}
// 文字宽度<320时,使用自动宽度,>320时,使用固定宽度320px,换行。
var $ctnWidth = $("#zwui-loading-cnt").width();
if($ctnWidth>320){
$loading.width(320+50);
}else{
$loading.width($ctnWidth);
}
// 用户可以输入固定宽度
if(opts.w || opts.h){
$loading.css({width:opts.w-10,height:opts.h-12,"line-height":"opts.h"-12});
}
return $loading;
},
_position : function($dom){
var $width = $dom.width();
var $height = $dom.height();
var clientWidth = $(window).width();
var clientHeight = $(window).height();
var _left = (clientWidth - $width)/2;
var _top = (clientHeight - $height)/2;
$dom.css({left:_left,top:_top});
return $dom;
},
_event : function(opts,$dom){
$dom.click(function(){
animates($dom,opts.mark);
});
},
_timer : function(opts,$dom){
var timer = null;
if(opts.time >= 0){
clearTimeout(timer);
timer = setTimeout(function(){
$dom.trigger("click");
},opts.time*1000);
}
}
};
/* 不用new的方式 */
var zwLoading = function(opts){
new zw_loading(opts);
};