6_动画.html 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. <style>
  9. #div1{
  10. width: 200px;
  11. height: 200px;
  12. background: aqua;
  13. transition: width 3s linear;
  14. }
  15. </style>
  16. </head>
  17. <body>
  18. <button id="up">放大</button>
  19. <div id="div1"></div>
  20. <button id="down">缩小</button>
  21. <script>
  22. var up = document.getElementById('up')
  23. var down = document.getElementById('down')
  24. var div1 = document.getElementById('div1')
  25. // up.onclick = function(){
  26. // var timer = setInterval(function(){
  27. // if(div1.offsetWidth >= 600){
  28. // clearInterval(timer)
  29. // }else{
  30. // div1.style.width = div1.offsetWidth + 10 + 'px'
  31. // console.log(div1.offsetWidth)
  32. // }
  33. // },10)
  34. // }
  35. // down.onclick = function(){
  36. // var timer1 = setInterval(function(){
  37. // if(div1.offsetWidth <= 200){
  38. // clearInterval(timer1)
  39. // } else {
  40. // div1.style.width = div1.offsetWidth - 10 +'px'
  41. // }
  42. // },10)
  43. // }
  44. up.onclick = function(){
  45. div1.style.width = '600px'
  46. }
  47. </script>
  48. </body>
  49. </html>