内置过渡动画
Element Plus 内应用在部分组件的过渡动画,你也可以直接使用。 在使用之前,请阅读 官方的过渡组件文档 。
Fade 淡入淡出
提供 el-fade-in-linear
和 el-fade-in
两种效果。
<template>
<div>
<el-button @click="show = !show">Click Me</el-button>
<div style="display: flex; margin-top: 20px; height: 100px">
<transition name="el-fade-in-linear">
<div v-show="show" class="transition-box">.el-fade-in-linear</div>
</transition>
<transition name="el-fade-in">
<div v-show="show" class="transition-box">.el-fade-in</div>
</transition>
</div>
</div>
</template>
<script lang="ts" setup>
import { ref } from 'vue'
const show = ref(true)
</script>
<style>
.transition-box {
margin-bottom: 10px;
width: 200px;
height: 100px;
border-radius: 4px;
background-color: #409eff;
text-align: center;
color: #fff;
padding: 40px 20px;
box-sizing: border-box;
margin-right: 20px;
}
</style>
Zoom 缩放
提供 el-zoom-in-center
,el-zoom-in-top
和 el-zoom-in-bottom
三种效果。
<template>
<div>
<el-button @click="show = !show">Click Me</el-button>
<div style="display: flex; margin-top: 20px; height: 100px">
<transition name="el-zoom-in-center">
<div v-show="show" class="transition-box">.el-zoom-in-center</div>
</transition>
<transition name="el-zoom-in-top">
<div v-show="show" class="transition-box">.el-zoom-in-top</div>
</transition>
<transition name="el-zoom-in-bottom">
<div v-show="show" class="transition-box">.el-zoom-in-bottom</div>
</transition>
</div>
</div>
</template>
<script lang="ts" setup>
import { ref } from 'vue'
const show = ref(true)
</script>
<style>
.transition-box {
margin-bottom: 10px;
width: 200px;
height: 100px;
border-radius: 4px;
background-color: #409eff;
text-align: center;
color: #fff;
padding: 40px 20px;
box-sizing: border-box;
margin-right: 20px;
}
</style>
Collapse 折叠面板
使用 el-collapse-transition
组件实现折叠展开效果。
<template>
<div>
<el-button @click="show = !show">Click Me</el-button>
<div style="margin-top: 20px; height: 200px">
<el-collapse-transition>
<div v-show="show">
<div class="transition-box">el-collapse-transition</div>
<div class="transition-box">el-collapse-transition</div>
</div>
</el-collapse-transition>
</div>
</div>
</template>
<script lang="ts" setup>
import { ref } from 'vue'
const show = ref(true)
</script>
<style>
.transition-box {
margin-bottom: 10px;
width: 200px;
height: 100px;
border-radius: 4px;
background-color: #409eff;
text-align: center;
color: #fff;
padding: 40px 20px;
box-sizing: border-box;
margin-right: 20px;
}
</style>
按需导入
// collapse
import { ElCollapseTransition } from 'element-plus'
// fade/zoom
import 'element-plus/lib/theme-chalk/base.css'
import App from './App.vue'
const app = createApp(App)
app.component(ElCollapseTransition.name, ElCollapseTransition)