vue动画效果-定义动画帧&过度效果&集成第三方动画animate.css

1.定义动画帧

<template>
  <div>
      <button @click="isShow=!isShow">显示/隐藏</button>
    <!-- //   :appear="true"表示加载即带有动画效果 -->
      <transition :appear="true">
      <div class="st" v-show="isShow">
            <h2>学生姓名:{{name}}</h2>
            <h2>学生性别:{{sex}}</h2>
      </div>

      </transition>
      <!-- 也可以自己设置名字 -->
      <transition name="hello" :appear="true">
          <h2 class="hi" v-show="isShow">你好</h2>
      </transition>
  </div>
</template>

<script>
export default {
    data() {
        return {
            name:"张三",
            sex:"男",
            isShow:true
        }
    }
}
</script>

<style scoped>
.st{
    background-color: aqua;
}
.hi{
    background-color: blanchedalmond;
}
/* 定义一个动画帧 */
@keyframes stu {
    from{
        transform: translateX(-100%);
    }
    to{
        transform: translateX(0px);
    }
}
/* 不命名固定格式 */
.v-enter-active{
    animation: stu 1s;
}
.v-leave-active{
    /* 反转 */
    animation: stu 1s reverse;
}

/* 自己命名固定格式 */
.hello-enter-active{
    /* linear匀速 */
    animation: stu 1s linear;
}
.hello-leave-active{
    /* 反转 */
    animation: stu 1s reverse;
}
</style>

2.过度效果

<template>
  <div>
      <button @click="isShow=!isShow">显示/隐藏</button>
      <transition-group :appear="true">
          <h2 v-show="isShow" key="1">学校</h2>
          <h2 v-show="isShow" key="2">清华</h2>
      </transition-group>
  </div>
</template>

<script>
export default {
    data() {
        return {
            isShow:true
        }
    },
}
</script>

<style scoped>
    h2{
        background-color: chartreuse;
    }
    /* 进入的起点 */ /* 离开的终点 */
    .v-enter,.v-leave-to{
        transform: translateX(-100%);
    }
    /* 进入的终点 *//* 离开的起点 */
    .v-enter-to,.v-leave{
        transform: translateX(0);
    }
    .v-enter-active,.v-leave-active{
        transition: 1s linear;
    }
</style>

3.集成第三方动画animate.css

*npm第三方动画库:npm官网下搜索animate.css

进入主页面:

 

*安装第三方库:npm install animate.css

*引入:import 'animate.css'

*使用:

1.引入类名:name="animate__animated animate__bounce"

   2.添加进入动画:enter-active-class="animate__swing"

3.添加离开动画:

leave-active-class=” animate__bounceOutDown”

 

<template>
  <div>
      <button @click="isShow=!isShow">显示/隐藏</button>

            <!-- 引入类名:name="animate__animated animate__bounce" -->
            <!-- 去库里选一个进入的动画 -->
            <!-- 选离开的动画 -->
      <transition :appear="true"
      name="animate__animated animate__bounce" 
      enter-active-class="animate__swing"
      leave-active-class="animate__bounceOutDown">
        <h2 v-show="isShow">集成第三方动画</h2>
      </transition>
  </div>
</template>

<script>
import 'animate.css'
export default {
    data() {
        return {
            isShow:true
        }
    },
}
</script>

<style scoped>
    h2{
        background-color: deeppink;
    }
</style>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

桃桃tao

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值