-
Notifications
You must be signed in to change notification settings - Fork 0
/
loading-spinner.js
62 lines (61 loc) · 1.66 KB
/
loading-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
/*
*/
'use strict';
function Spinner(){
Spinner.element=document.createElementNS('http://www.w3org/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')
};