내장 트랜지션
내장 트랜지션 (Built-in Transitions)
출처: 문서
본문
Element의 내장 트랜지션을 바로 사용할 수 있어요. 그 전에 트랜지션 문서를 먼저 읽어 보시길 권해요.
Fade
두 가지 페이드 효과가 있어요: el-fade-in-linear과 el-fade-in.
.el-fade-in-linear
.el-fade-in
<template>
<div class="fade-container">
<el-button @click="show = !show">Toggle</el-button>
<transition name="el-fade-in">
<div v-show="show" class="transition-box">.el-fade-in</div>
</transition>
</div>
</template>
<script setup lang="ts">
import { ref } from 'vue'
const show = ref(true)
</script>
<style>
.fade-container {
display: flex;
flex-wrap: wrap;
gap: 16px;
min-height: 100px;
margin-top: 20px;
}
.transition-box {
width: 200px;
height: 100px;
border-radius: var(--el-border-radius-base);
background-color: var(--el-color-primary);
text-align: center;
color: #fff;
padding: 40px 20px;
box-sizing: border-box;
}
</style>
Zoom
el-zoom-in-left, el-zoom-in-center, el-zoom-in-top, el-zoom-in-bottom이 제공돼요.
.el-zoom-in-left
.el-zoom-in-center
.el-zoom-in-top
.el-zoom-in-bottom
<template>
<div>
<el-button @click="show = !show">Toggle</el-button>
<div class="transition-container">
<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 setup lang="ts">
import { ref } from 'vue'
const show = ref(true)
</script>
<style>
.transition-container {
display: flex;
margin-top: 20px;
min-height: 100px;
flex-wrap: wrap;
gap: 16px;
}
.transition-box {
width: 200px;
height: 100px;
border-radius: var(--el-border-radius-base);
background-color: var(--el-color-primary);
text-align: center;
color: #fff;
padding: 20px;
box-sizing: border-box;
display: flex;
align-items: center;
justify-content: center;
word-break: break-word;
font-size: 14px;
}
</style>
Collapse
접기(collapse) 효과에는 el-collapse-transition 컴포넌트를 사용해요.
el-collapse-transition
<template>
<div>
<el-button @click="show = !show">Toggle</el-button>
<el-collapse-transition>
<div v-show="show" class="transition-box">el-collapse-transition</div>
</el-collapse-transition>
</div>
</template>
<script setup lang="ts">
import { ref } from 'vue'
const show = ref(true)
</script>
<style>
.transition-box {
width: 200px;
height: 100px;
border-radius: var(--el-border-radius-base);
background-color: var(--el-color-primary);
text-align: center;
color: #fff;
padding: 40px 20px;
box-sizing: border-box;
}
</style>
온디맨드 import
main.ts
// collapse
import { ElCollapseTransition } from 'element-plus'
// fade/zoom
import 'element-plus/theme-chalk/base.css'
import App from './App.vue'
const app = createApp(App)
app.component(ElCollapseTransition.name, ElCollapseTransition)