内置过渡动画

Element 内应用在部分组件的过渡动画,你也可以直接使用。在使用之前请阅读 transition 组件文档

fade 淡入淡出

提供 el-fade-in-linearel-fade-in 两种效果。

  1. <template>
  2. <div>
  3. <el-button @click="show = !show">Click Me</el-button>
  4. <div style="display: flex; margin-top: 20px; height: 100px;">
  5. <transition name="el-fade-in-linear">
  6. <div v-show="show" class="transition-box">.el-fade-in-linear</div>
  7. </transition>
  8. <transition name="el-fade-in">
  9. <div v-show="show" class="transition-box">.el-fade-in</div>
  10. </transition>
  11. </div>
  12. </div>
  13. </template>
  14. <script>
  15. export default {
  16. data: () => ({
  17. show: true
  18. })
  19. }
  20. </script>
  21. <style>
  22. .transition-box {
  23. margin-bottom: 10px;
  24. width: 200px;
  25. height: 100px;
  26. border-radius: 4px;
  27. background-color: #409EFF;
  28. text-align: center;
  29. color: #fff;
  30. padding: 40px 20px;
  31. box-sizing: border-box;
  32. margin-right: 20px;
  33. }
  34. </style>
  35. ¶ zoom 缩放
  36. .el-zoom-in-center
  37. .el-zoom-in-top
  38. .el-zoom-in-bottom
  39. 提供 el-zoom-in-center,el-zoom-in-top 和 el-zoom-in-bottom 三种效果。
  40. <template>
  41. <div>
  42. <el-button @click="show2 = !show2">Click Me</el-button>
  43. <div style="display: flex; margin-top: 20px; height: 100px;">
  44. <transition name="el-zoom-in-center">
  45. <div v-show="show2" class="transition-box">.el-zoom-in-center</div>
  46. </transition>
  47. <transition name="el-zoom-in-top">
  48. <div v-show="show2" class="transition-box">.el-zoom-in-top</div>
  49. </transition>
  50. <transition name="el-zoom-in-bottom">
  51. <div v-show="show2" class="transition-box">.el-zoom-in-bottom</div>
  52. </transition>
  53. </div>
  54. </div>
  55. </template>
  56. <script>
  57. export default {
  58. data: () => ({
  59. show2: true
  60. })
  61. }
  62. </script>
  63. <style>
  64. .transition-box {
  65. margin-bottom: 10px;
  66. width: 200px;
  67. height: 100px;
  68. border-radius: 4px;
  69. background-color: #409EFF;
  70. text-align: center;
  71. color: #fff;
  72. padding: 40px 20px;
  73. box-sizing: border-box;
  74. margin-right: 20px;
  75. }
  76. </style>

collapse 展开折叠

使用 el-collapse-transition 组件实现折叠展开效果。

  1. <template>
  2. <div>
  3. <el-button @click="show3 = !show3">Click Me</el-button>
  4. <div style="margin-top: 20px; height: 200px;">
  5. <el-collapse-transition>
  6. <div v-show="show3">
  7. <div class="transition-box">el-collapse-transition</div>
  8. <div class="transition-box">el-collapse-transition</div>
  9. </div>
  10. </el-collapse-transition>
  11. </div>
  12. </div>
  13. </template>
  14. <script>
  15. export default {
  16. data: () => ({
  17. show3: true
  18. })
  19. }
  20. </script>
  21. <style>
  22. .transition-box {
  23. margin-bottom: 10px;
  24. width: 200px;
  25. height: 100px;
  26. border-radius: 4px;
  27. background-color: #409EFF;
  28. text-align: center;
  29. color: #fff;
  30. padding: 40px 20px;
  31. box-sizing: border-box;
  32. margin-right: 20px;
  33. }
  34. </style>

按需引入

  1. // fade/zoom 等
  2. import 'element-ui/lib/theme-chalk/base.css';
  3. // collapse 展开折叠
  4. import CollapseTransition from 'element-ui/lib/transitions/collapse-transition';
  5. import Vue from 'vue'
  6. Vue.component(CollapseTransition.name, CollapseTransition)