Vue单元素/组件进入/离开过渡

<template>
  <div class="page">
    <h1>单元素/组件过渡</h1>
    <!--为.box元素添加进入/离开过渡-->
    <transition name="fade" v-for="item in items">
      <div class="box" v-if="item.isShow" @click="item.isShow=!item.isShow">{{item.txt}}</div>
      <!--
      注意:transition的过渡效果只对第一层元素生效
      transition的name属性和css的前缀相对应,必须保持一致才能生效
      transition还要配合css一起使用才能生效
      -->
    </transition>
    <!--
    把需要添加过渡的元素放到transiton组件中
    -->
  </div>
</template>

<script>
  export default {
    name: 'HelloWorld',
    data() {
      return {
        items: [
          {txt: 'h', isShow: true},
          {txt: 'e', isShow: true},
          {txt: 'l', isShow: true},
          {txt: 'l', isShow: true},
          {txt: 'o', isShow: true}
        ]
      }
    }
  }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
  .page {
    display: flex;
  }

  .box {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 30px;
    font-weight: bold;
    width: 100px;
    height: 100px;
    background-color: #eee;
    margin: 0 30px;
  }

  /*
  过渡的类名
  如果transition元素没有name属性,则css元素默认前缀是 v-
  */
  .fade-leave-active {
    transition-property: opacity, transform;
    transition-duration: 0.5s, 0.5s;
  }
  .fade-leave-to /* .fade-leave-active below version 2.1.8 */ {
    opacity: 0;
    transform: scale(1.3);
  }
</style>

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值