Vue3 路由页面切换动画 animate.css

本文介绍如何使用 animate.css 库实现网页上的动画效果。包括安装步骤、在 Vue 路由中设置过渡动画及在组件中控制动画的示例。通过实际案例展示了动画在页面加载和组件切换时的应用。

animate.css官网

可以通过以下的内容,来获取自己想要的动态切换样式

在这里插入图片描述

1 路由动画transition或者在组件中控制使用animate

  • 安装
npm install animate.css
  • 在main.ts中引入
import 'animate.css/animate.min.css' //引入动画
  • 使用

在需要切换路由的页面中添加如下内容

html

<router-view v-slot="{ Component }">
   <transition name="router_animate">
     	<component :is="Component" />
   </transition>
</router-view>

css

.router_animate-enter-active {
    animation: slideInLeft 0.5s;
}
.router_animate-leave-active {
    animation: slideOutLeft 0.3s;
}

1.2 呈现结果

在这里插入图片描述

2 用于组件

控制类名是否加在元素上,值得注意的是,元素前面要加上animate__animated的前缀,下图:控制是否显示animate__bounce这个动画,flipinIntrue的时候

const flipinIn = ref(false); 
<el-button type="primary" @click=" flipinIn= true">animate.css实现</el-button>
<h1 class="animate__animated" :class="{animate__bounce:flipinIn}">动画文字</h1>

2.1 呈现结果

在这里插入图片描述

评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值