<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
.box{
width:800px;
height:40px;
border:3px solid #333;
}
.inner{
height:40px;
width:0%;
background:#369;
}
.inner2{
-webkit-transition:all 3s linear;
-moz-transition:all 3s linear;
-ms-transition:all 3s linear;
-o-transition:all 3s linear;
transition:all 3s linear;
}
</style>
</head>
<body>
<h1>滚动条</h1>
<hr>
<div class="box">
<div class="inner" id="inner"></div>
</div>
<button onclick="scrollBar()">开始</button>
<script>
//进度变量
var m = 0;
//进度条开始
function scrollBar(){
//判断是否结束
if (m >= 100) {
return;
}
m ++;
document.getElementById('inner').style.width = m+'%';
//定时
setTimeout(scrollBar, 100);
}
</script>
<br>
<br>
<br>
<br>
<br>
<br>
<div class="box">
<div class="inner inner2" id="inner2"></div>
</div>
<button onclick="transitionBar()">开 始</button>
<script>
function transitionBar(){
document.getElementById('inner2').style.width = "100%";
}
</script>
</body>
</html>
网友评论