forked from dhairyagothi/100_days_100_web_project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprogress_bar.js
54 lines (46 loc) · 1.5 KB
/
progress_bar.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
// let value = document.querySelector('#num');
// let progress = document.querySelector('.block2');
// let button = document.querySelector('#btn');
// let start = 0 ;
// let end = 90;
// let speed = 100;
// let timer = setInterval(function() {
// if (start >= end) {
// clearInterval(timer);
// }
// progress.style.background = `conic-gradient(#52c234 ${start * 3.6}deg, #061700 ${start * 3.6}deg, #52c234 ${start * 3.6}deg, white ${0}deg)`;
// value.textContent = `${start}%`;
// start++;
// }, speed);
// button.addEventListener('click', setInterval(timer, speed));
let value = document.querySelector('#num');
let progress = document.querySelector('.block2');
let button = document.querySelector('#btn');
let start = 0;
let end = 90;
let speed = 100;
let timer = null;
let isRunning = false;
// Function to update progress
function updateProgress() {
if (start >= end) {
clearInterval(timer);
isRunning = false;
return;
}
progress.style.background = `conic-gradient(#52c234 ${start * 3.6}deg, #061700 ${start * 3.6}deg, #52c234 ${start * 3.6}deg, white ${0}deg)`;
value.textContent = `${start}%`;
start++;
}
// Add click event listener to button
button.addEventListener('click', function () {
if (!isRunning) {
// Resume the timer
timer = setInterval(updateProgress, speed);
isRunning = true;
} else {
// Pause the timer
clearInterval(timer);
isRunning = false;
}
});