Skip to content

Commit 8b2133f

Browse files
committed
js简易版进度条
1 parent 75fd11b commit 8b2133f

2 files changed

Lines changed: 68 additions & 0 deletions

File tree

‎js简易进度条/index.html‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
7+
<title>简易版进度条</title>
8+
<link rel="stylesheet" href="./main.css">
9+
</head>
10+
<body>
11+
<!-- 最外层的容器 -->
12+
<div id="wrapper">
13+
<!-- 进度条容器 -->
14+
<div id="progressbar">
15+
<!-- 进度条 -->
16+
<div id="fill"></div>
17+
</div>
18+
</div>
19+
</body>
20+
<script>
21+
(function(){
22+
var progressbar = {
23+
init: function() {
24+
var fill = document.getElementById("fill");
25+
var count = 0;
26+
var timer = setInterval(() => {
27+
count++;
28+
fill.innerHTML=count + '%';
29+
if(count===100){
30+
clearInterval(timer)
31+
}
32+
}, 17);
33+
}
34+
};
35+
progressbar.init();
36+
})()
37+
</script>
38+
</html>

‎js简易进度条/main.css‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#wrapper {
2+
width: 200px;
3+
height: 100px;
4+
border: 1px solid #000000;
5+
margin: 0 auto;
6+
}
7+
#progressbar {
8+
width: 180px;
9+
height: 20px;
10+
margin: 0 auto;
11+
margin-top: 40px;
12+
border: 1px solid #000000;
13+
}
14+
/* 设置进度条动画 */
15+
#fill {
16+
animation: move 2s;
17+
text-align: center;
18+
background-color: #6caf00;
19+
color: #ffffff;
20+
}
21+
22+
/* 实现元素宽度过度的动画效果 */
23+
@keyframes move {
24+
0% {
25+
width: 0;
26+
}
27+
100% {
28+
width: 100%;
29+
}
30+
}

0 commit comments

Comments
 (0)