-
Notifications
You must be signed in to change notification settings - Fork 0
/
mask.js
76 lines (59 loc) · 1.31 KB
/
mask.js
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
/**
* 遮罩
*
* @example
* var mask = $('..').mask(); // 生成遮罩
* mask.render(); // 遮罩生效
* mask.remove();
*
*/
define(function(require) {
var $ = require('jquery');
var Mask = function(target, _config) {
this.mask = $('<div>');
this.config = {};
var config = {
loading: true, // 是否增加背景loading图片
layout: $('body'),
css: {
zIndex: 100
},
setPos: true
};
$.extend(this.config, config, _config);
var mask = this.mask;
// 遮罩层
mask.addClass('lg-mask').addClass('lg-lg-lg').css(this.config.css);
this.config.loading && mask.addClass('lg-ajax-loading');
this.config.loading && mask.append('<div class="ui active loader lg-fixed-loading"></div>');
this.target = target;
};
Mask.prototype = {
render: function() {
var mask = this.mask;
var config = this.config;
mask.css(this._size());
config.setPos && mask.css(this._position());
config.layout.append(mask);
return this;
},
remove: function() {
this.mask.remove();
return this;
},
_position: function() {
var pos = this.target.offset();
return {
top: pos ? pos.top : 0,
left: pos ? pos.left : 0
};
},
_size: function() {
return {
width: this.target.outerWidth(),
height: this.target.outerHeight()
};
}
};
return Mask;
});