7_动画.html 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. *{
  10. margin: 0;
  11. padding: 0;
  12. }
  13. #div1{
  14. width: 200px;
  15. height: 200px;
  16. background: red;
  17. transition: width 2s linear;
  18. }
  19. </style>
  20. </head>
  21. <body>
  22. <button id="up">放大</button>
  23. <div id="div1"></div>
  24. <button id="down">缩小</button>
  25. <script>
  26. var up = document.getElementById('up')
  27. var div1 = document.getElementById('div1')
  28. var down = document.getElementById('down')
  29. // up.onclick = function(){
  30. // var timer = setInterval(function(){
  31. // console.log(div1.offsetWidth)
  32. // if(div1.offsetWidth >= 500){
  33. // clearInterval(timer)
  34. // } else{
  35. // div1.style.width = div1.offsetWidth + 10 +'px'
  36. // }
  37. // },10)
  38. // }
  39. // down.onclick = function(){
  40. // var timer1 = setInterval(function(){
  41. // console.log(div1.offsetWidth)
  42. // if(div1.offsetWidth <= 200){
  43. // clearInterval(timer1)
  44. // } else {
  45. // div1.style.width = div1.offsetWidth - 10 +'px'
  46. // }
  47. // },10)
  48. // }
  49. up.onclick = function(){
  50. div1.style.width = '500px'
  51. }
  52. </script>
  53. </body>
  54. </html>