-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
53 lines (44 loc) · 1.56 KB
/
script.js
File metadata and controls
53 lines (44 loc) · 1.56 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
window.addEventListener("load", (event) => {
const progressBar = document.getElementById("progressbar");
var queryString = window.location.search;
var params = new URLSearchParams(queryString);
const setStyleProperty = (property, value) => {
if(value != null)
{
document.documentElement.style.setProperty(property, value);
}
};
const progressBar0 = document.querySelector('#progressbar');
const duration = params.get('duration');
setStyleProperty('--duration', duration);
setStyleProperty('--bgclr', params.get('bgclr'));
setStyleProperty('--bgstart', params.get('bgstart'));
setStyleProperty('--bgfinish', params.get('bgfinish'));
if(getComputedStyle(document.documentElement).getPropertyValue('--bgfinish') === 'white')
{
progressBar0.style.color = "black";
}
percent = params.get('percent');
valueWithoutPercent = percent.replace("%", "");
if(percent != null)
{
if(percent <= 0 || percent > 100)
{
throw "Invalid value entered";
} else {
percent1 = percent.toString();
percent2 = percent1 + "%";
progressBar0.setAttribute('data-percent', percent);
}
}
const percentValue = progressBar.getAttribute("data-percent");
let interval = setInterval(() => {
const computedStyle = getComputedStyle(progressBar);
const width = parseFloat(computedStyle.getPropertyValue('--width')) || 0;
progressBar.style.setProperty('--width', width + parseFloat((duration.replace("s", "") / 10) / 5));
if(Math.round(width) === Math.round(valueWithoutPercent))
{
clearInterval(interval);
}
}, 1)
});