内置过渡动画

Element Plus 内应用在部分组件的过渡动画,你也可以直接使用。 在使用之前,请阅读 官方的过渡组件文档 内置过渡动画 - 图1

Fade 淡入淡出

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

内置过渡动画 - 图2

  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 lang="ts" setup>
  15. import { ref } from 'vue'
  16. const show = ref(true)
  17. </script>
  18. <style>
  19. .transition-box {
  20. margin-bottom: 10px;
  21. width: 200px;
  22. height: 100px;
  23. border-radius: 4px;
  24. background-color: #409eff;
  25. text-align: center;
  26. color: #fff;
  27. padding: 40px 20px;
  28. box-sizing: border-box;
  29. margin-right: 20px;
  30. }
  31. </style>

Zoom 缩放

提供 el-zoom-in-centerel-zoom-in-topel-zoom-in-bottom 三种效果。

内置过渡动画 - 图3

  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-zoom-in-center">
  6. <div v-show="show" class="transition-box">.el-zoom-in-center</div>
  7. </transition>
  8. <transition name="el-zoom-in-top">
  9. <div v-show="show" class="transition-box">.el-zoom-in-top</div>
  10. </transition>
  11. <transition name="el-zoom-in-bottom">
  12. <div v-show="show" class="transition-box">.el-zoom-in-bottom</div>
  13. </transition>
  14. </div>
  15. </div>
  16. </template>
  17. <script lang="ts" setup>
  18. import { ref } from 'vue'
  19. const show = ref(true)
  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>

Collapse 折叠面板

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

内置过渡动画 - 图4

  1. <template>
  2. <div>
  3. <el-button @click="show = !show">Click Me</el-button>
  4. <div style="margin-top: 20px; height: 200px">
  5. <el-collapse-transition>
  6. <div v-show="show">
  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 lang="ts" setup>
  15. import { ref } from 'vue'
  16. const show = ref(true)
  17. </script>
  18. <style>
  19. .transition-box {
  20. margin-bottom: 10px;
  21. width: 200px;
  22. height: 100px;
  23. border-radius: 4px;
  24. background-color: #409eff;
  25. text-align: center;
  26. color: #fff;
  27. padding: 40px 20px;
  28. box-sizing: border-box;
  29. margin-right: 20px;
  30. }
  31. </style>

按需导入

  1. // collapse
  2. import { ElCollapseTransition } from 'element-plus'
  3. // fade/zoom
  4. import 'element-plus/lib/theme-chalk/base.css'
  5. import App from './App.vue'
  6. const app = createApp(App)
  7. app.component(ElCollapseTransition.name, ElCollapseTransition)