-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
113 lines (107 loc) · 3.13 KB
/
index.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
body{
background-color: grey;
}
.box{
width: 150px;
height: 60px;
border: 1px solid white;
padding: 10px;
background-color: rgba(0,0,0,0.6);
z-index: 0;
}
.box p{
font-size: 34px;
text-align: center;
line-height: 60px;
margin: 0;
font-weight: bolder;
color: white;
z-index: 1;
}
#trace{
height: 76px;
width: 4px;
background-color: rgba(255,255,255,0.6);
float: left;
position: relative;
top: -8px;
}
#loadingBar{
width: 320px;
height: 25px;
border: 1px solid white;
margin-top: 15px;
background-color: rgba(0,0,0,0.6);
}
#loaded{
width: 316px;
height: 21px;
background-color: white;
position: relative;
top: 2px;
left: 2px;
}
</style>
</head>
<body>
<div class="box">
<div id="trace" style="left: -8px"></div>
<p id="percent">0%</p>
</div>
<div id="loadingBar"><div id="loaded"></div></div>
<script>
let trace = document.getElementById('trace')
let percent = document.getElementById('percent')
let loaded = document.getElementById('loaded')
let isUp = true
var upPercent = ''
function pxToNumber(string) {
return Number(string.replace('px', ''))
}
function percentToNumber(string) {
return Number(string.replace('%', ''))
}
function changeTraceLeft() {
if (pxToNumber(trace.style.left) === 154) {
isUp = false
}
if (isUp) {
let newLeft = `${pxToNumber(trace.style.left) + 1}px`
trace.style.left = newLeft
} else {
if (pxToNumber(trace.style.left) === -8) {
isUp = true
}
let newLeft = `${pxToNumber(trace.style.left) - 1}px`
trace.style.left = newLeft
}
}
function increasePercent() {
let innerText = percent.innerText
if (percentToNumber(innerText) == 100) {
clearInterval(upPercent)
alert('carregado')
} else {
let n = percentToNumber(innerText)
let n2 = n + 1
let newPercent = `${n2}%`
percent.innerText = newPercent
loaded.style.width = `${n2 * 314 / 100}px`
}
}
function main() {
window.setInterval('changeTraceLeft()', 10)
upPercent = window.setInterval('increasePercent()', 100)
}
main()
</script>
</body>
</html>