-
Notifications
You must be signed in to change notification settings - Fork 1
/
js-ani.html
40 lines (39 loc) · 931 Bytes
/
js-ani.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
//html和css, use setTimeout method.
<!DOCTYPE html>
<html>
<head>
<title></title>
<style>
.box{
background-color: lightblue;
height: 20px;
line-height: 20px;
box-sizing: border-box;
}
</style>
</head>
<body>
<div class="box" style="width:0">0%</div>
<button id="btn">load</button>
<script>
var btn=document.getElementById('btn');
var div=document.getElementsByClassName('box')[0];
function load1(){
div.style.width=parseInt(div.style.width)+5+'px';
div.innerHTML=parseInt(div.style.width)/5+'%'
if(parseInt(div.style.width)<500){
var c=setTimeout(function(){
load1();
},16);
}else{
clearTimeout(c);
}
}
btn.addEventListener('click',function(){
load1();
//load2();
//load3();
});
</script>
</body>
</html>