vue 项目如何使用animate.css

 

 Animate.css是一款酷炫丰富的跨浏览器动画库,它在GitHub上的star数至今已有5.3万+。 在vue项目中我们可以借助于animate.css,用十分简单的代码来实现一个个炫酷的效果!(可以装B了)

一 、安装

在命令行中执行:

使用npm或者cnpm安装

npm install animate.css --save  或 cnpm install animate.css --save

使用yarn安装

yarn add animate.css

二、引入

在main.js全局引入

import animated from 'animate.css'
vue.use(animated)

三、页面使用

类名(animated )需要和引入的名称相同,bounceInLeft是需要的动画效果



<!-- 直接使用animated中的动画class名,注意:必须使用animated这个class名,否则动画会无效 -->
<div class="box animated bounceInLeft"></div>
<template>
    <div class="song">
        <p id="f" @click='fade'>hello</p>
    </div>
</template>
methods:{
    fade:function(){
        $('#f').addClass('animated bounceOutLeft')
    }
}

常用有

fade: {
        title: '淡入淡出',
        fadeIn: '淡入',
        fadeInDown: '向下淡入',
        fadeInDownBig: '向下快速淡入',
        fadeInLeft: '向右淡入',
        fadeInLeftBig: '向右快速淡入',
        fadeInRight: '向左淡入',
        fadeInRightBig: '向左快速淡入',
        fadeInUp: '向上淡入',
        fadeInUpBig: '向上快速淡入',
        fadeOut: '淡出',
        fadeOutDown: '向下淡出',
        fadeOutDownBig: '向下快速淡出',
        fadeOutLeft: '向左淡出',
        fadeOutLeftBig: '向左快速淡出',
        adeOutRight: '向右淡出',
        fadeOutRightBig: '向右快速淡出',
        fadeOutUp: '向上淡出',
        fadeOutUpBig: '向上快速淡出'
      },
      bounce: {
        title: '弹跳类',
        bounceIn: '弹跳进入',
        bounceInDown: '向下弹跳进入',
        bounceInLeft: '向右弹跳进入',
        bounceInRight: '向左弹跳进入',
        bounceInUp: '向上弹跳进入',
        bounceOut: '弹跳退出',
        bounceOutDown: '向下弹跳退出',
        bounceOutLeft: '向左弹跳退出',
        bounceOutRight: '向右弹跳退出',
        bounceOutUp: '向上弹跳退出'
      },
      zoom: {
        title: '缩放类',
        zoomIn: '放大进入',
        zoomInDown: '向下放大进入',
        zoomInLeft: '向右放大进入',
        zoomInRight: '向左放大进入',
        zoomInUp: '向上放大进入',
        zoomOut: '缩小退出',
        zoomOutDown: '向下缩小退出',
        zoomOutLeft: '向左缩小退出',
        zoomOutRight: '向右缩小退出',
        zoomOutUp: '向上缩小退出'
      },
      rotate: {
        title: '旋转类',
        rotateIn: '顺时针旋转进入',
        rotateInDownLeft: '从左往下旋入',
        rotateInDownRight: '从右往下旋入',
        rotateInUpLeft: '从左往上旋入',
        rotateInUpRight: '从右往上旋入',
        rotateOut: '顺时针旋转退出',
        rotateOutDownLeft: '向左下旋出',
        rotateOutDownRight: '向右下旋出',
        rotateOutUpLeft: '向左上旋出',
        rotateOutUpRight: '向右上旋出'
      },
      flip: {
        title: '翻转类',
        flipInX: '水平翻转进入',
        flipInY: '垂直翻转进入',
        flipOutX: '水平翻转退出',
        flipOutY: '垂直翻转退出'
      },
      strong: {
        title: '强调类',
        bounce: '弹跳',
        flash: '闪烁',
        pulse: '脉冲',
        rubberBand: '橡皮筋',
        shake: '左右弱晃动',
        swing: '上下摆动',
        tada: '缩放摆动',
        wobble: '左右强晃动',
        jello: '拉伸抖动'
      }

 

四、踩坑问题

如果完成前三部还是没有效果,可能就是animate.css版本的问题了,直接安装的都是最新版本,而vue官网引入的是3.5.1版本。更换一下版本:

先卸载:

npm或cnpm卸载:

npm uninstall animate.css --save
cnpm uninstall animate.css --save

或者 yarn卸载:

yarn remove animate.css

重新安装:

npm或cnpm安装:

npm install animate.css@3.5.1 --save
 cnpm install animate.css@3.5.1 --save

yarn安装:

yarn add animate.css@3.5.1

应该就木有问题了。

本文完〜希望能够帮到您,点个赞吧

posted @ 2021-12-09 17:45  喆星高照  阅读(1789)  评论(0编辑  收藏  举报