123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- <style>
- #div1{
- width: 200px;
- height: 200px;
- background: aqua;
- transition: width 3s linear;
- }
- </style>
- </head>
- <body>
- <button id="up">放大</button>
- <div id="div1"></div>
- <button id="down">缩小</button>
- <script>
- var up = document.getElementById('up')
- var down = document.getElementById('down')
- var div1 = document.getElementById('div1')
- // up.onclick = function(){
- // var timer = setInterval(function(){
- // if(div1.offsetWidth >= 600){
- // clearInterval(timer)
- // }else{
- // div1.style.width = div1.offsetWidth + 10 + 'px'
- // console.log(div1.offsetWidth)
- // }
- // },10)
- // }
- // down.onclick = function(){
- // var timer1 = setInterval(function(){
- // if(div1.offsetWidth <= 200){
- // clearInterval(timer1)
- // } else {
- // div1.style.width = div1.offsetWidth - 10 +'px'
- // }
- // },10)
- // }
- up.onclick = function(){
- div1.style.width = '600px'
- }
- </script>
- </body>
- </html>
|