fix
Helius
2022-09-22 ad22a1e5595b76436d005ba9f1f928ea094fe5c0
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
layui.define(['jquery'], function (exports) {
    var $ = layui.jquery;
    var self = {
        elem: null,
        barTimer: 0,
        barWidth: 0,
        config: {
            color: '#5a8bff',
            errorColor: '#FF5722',
            height: 2
        }
    };
 
    function randomNum(minNum, maxNum) {
        switch (arguments.length) {
            case 1:
                return parseInt(Math.random() * minNum + 1, 10);
            case 2:
                return parseInt(Math.random() * (maxNum - minNum + 1) + minNum, 10);
            default:
                return 0;
        }
    }
 
    function setBarWidth(num) {
        self.barWidth = num;
        self.elem.css('width', self.barWidth + '%');
    }
 
    function addBarWidth(num) {
        self.barWidth += num;
        if (self.barWidth >= 100) self.barWidth = 100;
        setBarWidth(self.barWidth);
        return self.barWidth;
    }
 
    function hideBar(barColor) {
        clearInterval(self.barTimer);
        addBarWidth(100);
        self.elem.css({'backgroundColor': barColor});
        setTimeout(function () {
            self.elem.css({
                'opacity': 0
            });
            setBarWidth(0);
        }, 250);
    }
 
    self.start = function (config) {
        this.config = $.extend(this.config, config || {});
        if (this.barTimer) {
            clearInterval(this.barTimer);
            setBarWidth(0);
        }
        if (this.elem == null) {
            this.elem = $('<div id="febs-loadbar"></div>');
            $('body').prepend(this.elem);
        }
        this.elem.css({
            'height': this.config.height,
            'backgroundColor': this.config.color,
            'position': 'fixed',
            'top': 0,
            'left': 0,
            'width': 0,
            'opacity': 1,
            'zIndex': 2000,
            'transition': 'all .2s linear'
        });
 
        addBarWidth(randomNum(1, 10));
        this.barTimer = setInterval(function () {
            addBarWidth(randomNum(1, 10));
            if (self.barWidth >= 75) self.barWidth = 75
        }, 160);
 
    };
    self.finish = function () {
        hideBar(this.config.color);
    };
    self.error = function () {
        hideBar(this.config.errorColor);
    };
    exports('loadBar', self);
});