1
81041
2019-10-18 cc4059f9f5a2cd6766f4d888bd35d19f3827a053
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
// 定义页面加载等待效果
function Loading() {
    this.cont = $(window);    // 容器
    this.height = this.cont.height();    // 容器的高度
    this.width = this.cont.width();    // 容器的宽度
}
 
Loading.prototype.showLoading = function(container) {
    this.hideLoading(container);
    var zIndex = '999997';
    var isBody = false;
    if(container != undefined) {
        this.cont = container;    // 重新定义容器
        zIndex = '999';
    }else {
        this.cont = $('body');
        isBody = true;
    }
    this.height = this.cont.height();    // 容器的高度
    this.width = this.cont.width();    // 容器的宽度
    this.cont.css('position', 'relative');
 
    var imgDiv = $('<div class="loading"></div>');
    // 容器是body
    if(isBody) {
        imgDiv.addClass('loading-fixed');
    }
    var img = $('<img src="image/loading-blue.gif" alt="loading">');
    imgDiv.append(img);
    var mask = $('<div class="loading-mask"></div>');
    mask.css({
        'position': 'absolute',
        'top': 0,
        'left': 0,
        'z-index': zIndex,
        'width': '100%',
        'height': this.height+'px',
        'background-color': '#3A3939',
        'filter':'alpha(opacity=210)', /*IE滤镜,透明度50%*/
        '-moz-opacity':0.1,    /*Firefox私有,透明度50%*/
        'opacity':0.1    /*其他,透明度50%*/
    });
    this.cont.append(mask);
    this.cont.append(imgDiv);
};
 
Loading.prototype.hideLoading = function(container) {
    //console.info("8888888888888888");
    if(container != undefined) {
        this.cont = container;    // 重新定义容器
        this.height = this.cont.height();    // 容器的高度
        this.width = this.cont.width();    // 容器的宽度
    }else {
        this.cont = $('body');
    }
    
    this.cont.children('.loading').remove();
    this.cont.children('.loading-mask').remove();
};
var loading = new Loading();