16.transition.html 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. <style>
  8. * {
  9. margin: 0;
  10. padding: 0;
  11. }
  12. #box {
  13. width: 200px;
  14. height: 200px;
  15. background: aqua;
  16. margin: 100px auto;
  17. transition: width 5s linear 1s;
  18. }
  19. </style>
  20. </head>
  21. <body>
  22. <!--
  23. transition允许css的属性值在一定的时间区间内平滑地过渡。
  24. transition主要包含四个属性值:
  25. transition-property:all 表示要参与过渡的属性 all是默认值
  26. transition-duration:3s 表示动画持续的时长和速度曲线 默认值0(时长决定速度)
  27. transition-timing-function:linear 动画运动的方式类型
  28. (ease:默认值 linear:匀速运动 ease-in:表示由慢到快 ease-out:表示由快到慢 ease-in-out:慢快慢)
  29. transition-delay:1s 动画的延迟时间
  30. IOS下safari渲染transition时出现闪屏问题,解决方法:
  31. backface-visibility:hidden;背面可见度
  32. display:none;的元素并不支持css3动画
  33. -->
  34. <div id="box"></div>
  35. <button id="btn">放大</button>
  36. <button id="btn1">缩小</button>
  37. <script>
  38. var box = document.getElementById("box");
  39. var btn = document.getElementById("btn");
  40. var btn1 = document.getElementById("btn1");
  41. btn.onclick = function() {
  42. box.style.width = 500 + 'px';
  43. }
  44. btn1.onclick = function() {
  45. box.style.width = 200 + 'px';
  46. }
  47. </script>
  48. </body>
  49. </html>