vue之内置的动画效果
fade 过度显示隐藏动画效果
精简写法1
<template>
<div class="home">
<button @click="btnShow">点击显示</button>
<!-- transition包裹一个元素后,这个元素的显示和隐藏就会自动添加一些类名 -->
<transition name="dialog">
<div v-show="visible">我是动画</div>
</transition>
</div>
</template>
<script>
export default {
name: "Home",
components: {
},
data() {
return {
visible: false,
};
},
methods: {
btnShow() {
this.visible = true;
},
},
};
</script>
<style lang="scss" scoped>
.dialog-enter-active {
animation: run 0.5s;
}
.dialog-leave-active {
animation: run 0.5s reverse;
}
@keyframes run {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
.home {
height: calc(100% - 34px);
width: calc(100% - 34px);
background: #fff;
padding: 16px;
border: 1px solid #ccc;
}
</style>
|