This repository was archived by the owner on Jul 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPreLoader.js
More file actions
55 lines (44 loc) · 1.37 KB
/
PreLoader.js
File metadata and controls
55 lines (44 loc) · 1.37 KB
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
import React, { Component } from 'react';
var preLoaderColor = "#777777ff",
Width = 200 ,
Height = 200 ,
AnimSpeed = 0.2 ;
export default class Preloader extends Component {
static setColor(newColor="#777777ff",width=200,height=200,animSpeed=0.2)
{
Width = width ;
Height = height ;
AnimSpeed = animSpeed ;
preLoaderColor = newColor ;
}
componentDidMount() {
//Start animation
/**@type {canvas} */
this.rad = 0 ;
this.ctx = this.refs.canvas.getContext('2d');
this.intervalId = setInterval(this.animate.bind(this),10);
}
componentWillUnmount(){
clearInterval(this.intervalId);
}
animate()
{
/**@type {canvas} */
let canvas = this.ctx ;
canvas.clearRect(0,0,Width,Height);
canvas.strokeStyle=preLoaderColor;
canvas.lineWidth=3;
canvas.beginPath();
canvas.arc(Width/2,Height/2,Width/4,this.rad,this.rad+Math.PI,false);
canvas.stroke();
canvas.beginPath();
canvas.arc(Width/2,Height/2,Width/4-2,this.rad-1,(this.rad+Math.PI-1),false);
canvas.stroke();
this.rad+=AnimSpeed ;
}
render() {
return (
<canvas style={{width:100,height:100,margin:'auto',display:'block'}} ref="canvas" width={Width} height={Height}/>
);
}
};