vue — 过度&动画 transition

本文深入探讨了Vue中的`transition`组件,它用于通过条件渲染来包裹多个元素,实现过渡效果。通过设置`mode`属性,可以精细控制元素的出场和入场动画顺序,从而创建丰富的视觉动态效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

过度

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .box{
      width: 150px;
      height: 150px;
      background-color: purple;
      margin: 50px auto;
    }
  
    .fade-enter{
      transform: translateX(-500px) rotate(-720deg) scale(0);
      opacity: 0;
    }
    .fade-enter-active,.fade-leave-active{
      transition: all 1s;
    }
    .fade-leave-to{
      transform:translateY(500px) rotate(720deg) scale(0);
    }
  </style>
</head>
<body>
  <div id="app">
    <button @click="show"> {{ isShow?'消失':'显示' }} </button>
    <transition name="fade">
      <div class="box" v-if="isShow"></div>
      
    </transition>
  </div>
  <script src="./vue.js"></script>
  <script>
    const vm = new Vue({
      el: '#app',
      data: {
        isShow: false
      },
      methods: {
        show(){
          this.isShow = !this.isShow;
        }
      }
    })
  </script>
</body>
</html>

transition组件通过条件渲染 包裹多个元素
添加mode属性控制 出场动画 和入场动画的 执行 顺序

## 动画

```html
定义动画
//关键针
<style>
@keyframes 动画名{
  0%{

  }
  25%{

  }
  50%{

  }
  75%{

  }
  100%{

  }
}
</style>
使用动画
animation-name
animation-duration
animation-delay
animation-timing-function linear ease ease-in 
animation-iteration-count    n infinite
animation-direction   normal reverse alternate alternate-reverse
animation-play-state pause running
animation-fill-mode forward backward both

animation: name duration delay 后面顺序随便
animation.css插件
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .box{
      width: 200px;
      height: 200px;
      background-color: red;
      margin: 50px auto;
    }
  </style>
  <link rel="stylesheet" href="./animate.css">
</head>
<body>
  <div class="box animate__animated animate__tada"></div>
</body>


## 列表动画  
<transition-group></ransition-group> 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值