index.html
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>Прогресс-бар</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div id="myProgress">
<div id="myBar">
<div id="label">10%</div>
</div>
</div>
<br />
<button onclick="move()">Click</button>
<script src="script.js"></script>
</body>
</html>
style.css
#myProgress {
position: relative;
width: 300px;
height: 30px;
background-color: #ddd;
}
#myBar {
position: absolute;
width: 10%;
height: 100%;
background-color: #4CAF50;
}
#label {
text-align: center;
line-height: 30px;
color: white;
}
script.js
function move() {
var elem = document.getElementById("myBar");
var width = 10;
var id = setInterval(frame, 10);
function frame() {
if(width >= 100) {
clearInterval(id);
}
else {
width++;
elem.style.width = width +'%';
document.getElementById("label").innerHTML = width*1 +'%';
}
}
}
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>Прогресс-бар</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div id="myProgress">
<div id="myBar">
<div id="label">10%</div>
</div>
</div>
<br />
<button onclick="move()">Click</button>
<script src="script.js"></script>
</body>
</html>
style.css
#myProgress {
position: relative;
width: 300px;
height: 30px;
background-color: #ddd;
}
#myBar {
position: absolute;
width: 10%;
height: 100%;
background-color: #4CAF50;
}
#label {
text-align: center;
line-height: 30px;
color: white;
}
script.js
function move() {
var elem = document.getElementById("myBar");
var width = 10;
var id = setInterval(frame, 10);
function frame() {
if(width >= 100) {
clearInterval(id);
}
else {
width++;
elem.style.width = width +'%';
document.getElementById("label").innerHTML = width*1 +'%';
}
}
}
Комментариев нет:
Отправить комментарий