-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcountdown-gauge.ts
65 lines (54 loc) · 1.49 KB
/
countdown-gauge.ts
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
import { cubicBezier, Gauge } from '../../../src';
import './countdown-gauge.scss';
const linear = cubicBezier(0, 0, 1, 1);
const easeIn = cubicBezier(0, 0, 0.2, 1);
function updateTimerNode(value: number) {
const timer = document.querySelector('.timer') as HTMLElement;
timer.innerHTML = value.toString();
}
function wait(ms: number) {
return new Promise(resolve => setTimeout(resolve, ms));
}
document.addEventListener('DOMContentLoaded', async () => {
let timer = 5;
updateTimerNode(timer);
const container = document.querySelector('.countdown-gauge') as HTMLElement;
const sharedConfig = {
container,
gaugeRadius: 45,
lineWidth: 1,
fromAngle: 0,
toAngle: 360,
animationDuration: 5000,
easing: linear
};
const maxValue = sharedConfig.toAngle - sharedConfig.fromAngle;
const gaugeBackground = new Gauge({
...sharedConfig,
color: '#ebebeb',
animationDuration: 0
});
gaugeBackground.setValue(maxValue);
const mainGauge = new Gauge({
...sharedConfig,
color: '#fd9eaa'
});
await mainGauge.setValue(maxValue, { animationDuration: 0 });
await wait(2000);
const interval = setInterval(() => {
timer--;
updateTimerNode(timer);
}, 1000);
await mainGauge.setValue(0, { easing: linear });
clearInterval(interval);
timer = 0;
updateTimerNode(timer);
await mainGauge.setValue(maxValue, {
easing: easeIn,
animationDelay: 600,
animationDuration: 600
});
await wait(500);
timer = 5;
updateTimerNode(timer);
});