Vue3第十章 (transtion基础组件使用)

本文介绍了如何在Vue.js中利用transition组件创建动画效果。通过设置name属性,如`fade`,并定义对应的进入和离开样式,如`.fade-enter-from`、`.fade-enter-active`等,可以实现元素的淡入淡出效果。示例代码展示了一个按钮切换显示红色方块的场景,详细说明了样式和Vue的transition结合使用的步骤。
摘要由CSDN通过智能技术生成

在transition组件上使用name属性,然后写对应动画的样式即可
例如:
name=“fade”
进入样式为:
fade-enter-from
fade-enter-active
fade-enter-to
离开样式为:
fade-leave-from
fade-leave-active
fade-leave-to

<template>
  <div class="content">
    <button @click="flag = !flag">switch</button>
    <transition name="fade">
      <div v-if="flag" class="box"></div>
    </transition>
  </div>  
</template>
<script setup lang="ts">
import { ref } from 'vue'

defineProps<{ msg: string }>()

const count = ref(0)

const flag = ref<boolean>(false)
</script>
<style scoped>
.content{
  width:600px;
  height:600px;
}
.box{
  width:200px;
  height:200px;
  background-color: red;
}
.fade-enter-from{
  width:0;
  height:0;
  transform: rotate(360deg);
}
.fade-enter-active{
  transition: all 1s ease;
}
.fade-enter-to{
  width:200px;
  height:200px;
}
.fade-leave-from{
  width:200px;
  height:200px;
  transform: rotate(360deg);
}
.fade-leave-active{
  transition: all 5s ease;
}
.fade-leave-to{
  width:0;
  height:0;
}
</style>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值