1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- <style>
- .box{
- width: 300px;
- height: 300px;
- box-shadow: 0 0 10px rgba(0,0,0.5);
- background-color: #aaa;
- border-radius: 10px;
- position: fixed;
- top:50%;
- left: 50%;
- margin-left:-150px;
- margin-top: -150px;
- text-align: center;
- }
- .btn{
- width: 100px;
- height: 40px;
- line-height: 40px;
- margin:0 auto;
- border:1px solid #666;
- cursor: pointer;
- }
- .box h1{
- margin-top: 100px;
- }
- </style>
- </head>
- <body>
- <div class="box">
- <h1>100</h1>
- <div class="btn">开始</div>
- </div>
- <script>
- var oH1 = document.getElementsByTagName("h1")[0];
- var oBtn = document.getElementsByClassName("btn")[0];
- var time = null;
- var isPlay = false;
- oBtn.onclick = function(){
- if(isPlay){
- //暂停状态
- this.innerText = "开始";
- isPlay = false;
- clearInterval(timer);
- }else{
- //开始状态
- isPlay = true;
- this.innerText = "暂停";
- timer = setInterval(function(){
- oH1.innerText = parseInt(oH1.innerText)-1
- },1000)
- }
- }
- </script>
- </body>
- </html>
|