-
Notifications
You must be signed in to change notification settings - Fork 0
/
spinner.js
117 lines (59 loc) · 2.03 KB
/
spinner.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
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
'use strict';
function Spinner() {
Spinner.element = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
let c = document.createElementNS('http://www.w3.org/2000/svg', 'circle');
Spinner.element.setAttribute('width', '100');
Spinner.element.setAttribute('height', '100');
c.setAttribute('viewBox', '0 0 100 100');
c.setAttribute('cx', '50');
c.setAttribute('cy', '50');
c.setAttribute('r', '42');
c.setAttribute('stroke-width', '16');
c.setAttribute('stroke', '#2196f3');
c.setAttribute('fill', 'transparent');
Spinner.element.appendChild(c);
Spinner.element.style.cssText = 'position:absolute;left:calc(50% - 50px);top:calc(50% - 50px)';
document.body.appendChild(Spinner.element)
}
Spinner.id = null;
Spinner.element = null;
Spinner.show = function () {
const c = 264, m = 15;
Spinner.element.style.display = 'block';
move1();
function move1() {
let i = 0, o = 0;
move();
function move() {
if (i == c) move2();
else {
i += 4; o += 8;
Spinner.element.setAttribute('stroke-dasharray', i + ' ' + (c - i));
Spinner.element.setAttribute('stroke-dashoffset', o)
Spinner.id = setTimeout(move, m)
}
}
}
function move2() {
let i = c, o = c * 2;
move();
function move() {
if (i == 0) move1();
else {
i -= 4; o += 4;
Spinner.element.setAttribute('stroke-dasharray', i + ' ' + (c - i));
Spinner.element.setAttribute('stroke-dashoffset', o)
Spinner.id = setTimeout(move, m)
}
}
}
};
Spinner.hide = function () {
Spinner.element.style.display = 'none';
if (Spinner.id) {
clearTimeout(Spinner.id);
Spinner.id = null
}
Spinner.element.setAttribute('stroke-dasharray', '0 264');
Spinner.element.setAttribute('stroke-dashoffset', '0')
};