vue项目项目使用animate.css动画效果

文章介绍了如何在Vue项目中使用animate.css进行动画效果的添加,包括安装、引入和使用方法。同时,讲解了结合Vue的过渡系统自定义动画类名。此外,还详细阐述了如何安装和配置wow.js来实现滚动时的动画显示,包括全局和局部引入的方式以及初始化设置。

animate.css使用

安装

npm i animate.css

引入

在main.ts文件中引入

// 引入动画库
import "animate.css"

使用

注意安装animate.css版本,我这里用的v4.1.1 ,animate__animated是基类必须使用的(因为安装的animate版本是4.x,使用时要注意对应的所有类名都以animate__开头,并且还要配合animate__animated一起使用!)

//注意这里必须加animate__animated基类
<div class="animate__animated animate__fadeInDown"></div>

在这里插入图片描述

在vue中使用过渡&动画里的内容

结合了vue中过渡&动画里的内容,自定义过渡 class 类名。
可以通过以下 attribute 来自定义过渡类名:

  • enter-from-class
  • enter-active-class
  • enter-to-class
  • leave-from-class
  • leave-active-class
  • leave-to-class
  <div
    enter-active-class="animate__animated animate__bounce"
    leave-active-class="animate__animated animate__bounce"
  >
    将要添加动画效果的dom元素
  </div>








animate.css官网 具体参数参考这里








wow.js:滚动时显示动画

有时需要搭配 wow.js实现动画

安装

npm install wow.js

npm i animate.css

引入

在main.ts文件中引入

// 引入动画库
import "animate.css"

全局引入

在main.ts 或者App.vue中初始化

import WOW from 'wow.js';

  let wow = new WOW({
  boxClass: 'wow', // animated element css class (default is wow)
  animateClass: 'animated', // animation css class (default is animated)
  offset: 0, // distance to the element when triggering the animation (default is 0)
  mobile: true, // trigger animations on mobile devices (default is true)
  live: true, // act on asynchronously loaded content (default is true)
  callback: function (box: any) {
    // the callback is fired every time an animation is started
    // the argument that is passed in is the DOM node being animated
  },
  scrollContainer: null, // optional scroll container selector, otherwise use window
  });
wow.init();


局部引入

在需要的组件中引用wow.js
import WOW from 'wow.js';

在生命周期里中初始化wow.js


  let wow = new WOW({
  boxClass: 'wow', // animated element css class (default is wow)
  animateClass: 'animated', // animation css class (default is animated)
  offset: 0, // distance to the element when triggering the animation (default is 0)
  mobile: true, // trigger animations on mobile devices (default is true)
  live: true, // act on asynchronously loaded content (default is true)
  callback: function (box: any) {
    // the callback is fired every time an animation is started
    // the argument that is passed in is the DOM node being animated
  },
  scrollContainer: null, // optional scroll container selector, otherwise use window
  });
 wow.init();


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

夜空孤狼啸

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

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

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

打赏作者

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

抵扣说明:

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

余额充值