-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprogressBar.html
55 lines (47 loc) · 1.46 KB
/
progressBar.html
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
<!DOCTYPE html>
<head>
<link rel="stylesheet" href="style_progressBar.css">
</head>
<body>
<h3>demo for progress bar</h3>
<div class="container">
<div id="progress_container">
<div id="progress"></div>
</div>
</div>
<button type="button" onclick="increase()">Click to progress</button>
<div class="form">
<input type="text" id="input">
<button type="button" onclick="setProgress()">set</button>
</div>
<script>
var INCREMENT = 10;
function increase() {
// 1. get the current width
var elem_progress = document.getElementById("progress");
var elem_progressBar =document.getElementById("progress_container");
var progressWidth = elem_progress.offsetWidth;
var progressBarWidth = elem_progressBar.offsetWidth;
var wid = Math.round((progressWidth/progressBarWidth)*100);
// console.log(wid);
// 2. increase the wid, stop when it's 100
if(wid >= 100){
wid = 0;
} else {
wid += INCREMENT;}
// 3. increase the progress
elem_progress.style.width = wid + "%";
}
function setProgress() {
var widInput = document.getElementById("input").value;
// 1. if the input is empty, set wid to 0
if(widInput == "") {
widInput = 0;
// console.log("aaa");
}
console.log(widInput);
var elem_progress = document.getElementById("progress");
elem_progress.style.width = widInput + "%";
}
</script>
</body>