一:使用animate.css的使用

1.安装npm install animate.css --save

2.在main.js中引入import animate from 'animate.css'

3.组件中使用

<transition name='fade' enter-active-class='animated flash' leave-active-class='animated shake'>
<p v-show='show'>动画</p>
</transition>
<button @click="handleClick">切换动画</button>

主要是在使用动画的外面嵌套transtion标签,加了name、enter-active-class、leave-active-class这样基本就实现了简单的动画,但是刷新页面并不会有动画,要实现要加appear、appear-active-class来实现初始化动画

<transition name='fade' appear appear-active-class='animated flash' enter-active-class='animated flash' leave-active-class='animated shake'>
<p v-show='show'>动画</p>
</transition>
<button @click="handleClick">切换动画</button>

这样就实现了刷新页面也有动画。如果想要在动画过程加transition,过度时间,可以这样写:

<transition name='fade' appear appear-active-class='animated flash' enter-active-class='animated flash fade-enter-active' leave-active-class='animated shake fade-leave-active'>
<p v-show='show'>动画</p>
</transition>
<button @click="handleClick">切换动画</button> <style scoped="scoped">
.fade-enter, .fade-leave-to{
opacity:0;
}
.fade-enter-active,.fade-leave-active{
transition: opacity 3s;
}
</style>

这样就实现了3s的过渡时间动画。但是这样有个问题是:我们用的animate.css库中实现flash等的时间是1s,而我们这里写的是3s,以哪个为准呢,vue也不知道,这里我们需要在transition 标签中加type属性,说明是以哪种为准。

<transition name='fade' type='transition' appear appear-active-class='animated flash' enter-active-class='animated flash fade-enter-active' leave-active-class='animated shake fade-leave-active'>
<p v-show='show'>动画</p>
</transition>
<button @click="handleClick">切换动画</button>

还可以自定义动画时长

<transition :duration='5000' name='fade' appear appear-active-class='animated flash' enter-active-class='animated flash fade-enter-active' leave-active-class='animated shake fade-leave-active'>
<p v-show='show'>动画</p>
</transition>

复杂一点为:

<transition :duration='{enter:5000,leave:5000}' name='fade' appear appear-active-class='animated flash' enter-active-class='animated flash fade-enter-active' leave-active-class='animated shake fade-leave-active'>
<p v-show='show'>动画</p>
</transition>

如果页面中是多个元素或组件的过渡,可以参考下面的写法:

1.多个元素

这里没有引入animate.css也可以,注意的是一定要加key值,否则没有效果,因为不加key,vue会在切换时候复用dom,加不同的key可以使得vue不复用dom。在transition标签加mode='in-out'实现了先进入再隐藏。在transition标签加mode='out-in'实现了先隐藏再显示。

<template>
<div class="toggle_box">
<transition mode='in-out'>
<div v-if='show' key='hello'>hello word</div>
<div v-else key='bye'>bye word</div>
</transition>
<button @click="handleclick">切换</button>
</div>
</template> <script>
export default{
data(){
return{
show:'true'
}
},
methods:{
handleclick(){
this.show=!this.show;
}
}
}
</script> <style>
.v-enter, .v-leave-to{
opacity: 0;
}
.v-enter-active, .v-leave-active{
transition: opacity 1s;
}
</style>

2.多个组件的过渡(按照上面的方法也可以实现)下面说一种动态组件的方法

参考地址:https://blog.csdn.net/q3254421/article/details/84593430

<template>
<div class="dy">
<transition mode='out-in'>
<component :is='type'></component>
</transition>
<button @click="handleClick">切换</button>
</div>
</template> <script>
import dyOne from './dynamic_one.vue'
import dyTwo from './dynamic_two.vue'
export default{
data(){
return{
type:'dy-one'
}
},
components:{
'dy-one':dyOne,
'dy-two':dyTwo
},
methods:{
handleClick:function(){
this.type=(this.type === 'dy-one'?'dy-two':'dy-one')
}
}
}
</script> <style>
.v-enter, .v-leave-to{
opacity: 0;
}
.v-enter-active, .v-leave-active{
transition: opacity 1s;
}
</style>

动态组件主要是component 来实现。

附:部分api

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: '拉伸抖动'
} 附录:页面未加载完之前显示加载中的动画
https://blog.csdn.net/weixin_42568343/article/details/82499625

vue中使用animate.css的更多相关文章

  1. vue中使用animate.css动画库

    1.安装: npm install animate.css --save 2.引入及使用: //main.js中 import animated from 'animate.css' Vue.use( ...

  2. 在vue中使用animate.css

    animate.css是一款前端动画库,相似的有velocity-animate 用法: 首先 npm install animate.css --save 然后在vue文件的script中引入: i ...

  3. 048——VUE中使用animate.css动画库控制vue.js过渡效果

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. vue中使用animate.css实现动画

    参考链接:https://www.cnblogs.com/ccyinghua/p/7872694.html 参考链接:https://www.jianshu.com/p/2e0b2f8d40cf 使用 ...

  5. vue项目中引入animate.css和wow.js

    本文转自:https://blog.csdn.net/liyunkun888/article/details/85003152 https://www.zhuimengzhu.com/content/ ...

  6. vue+ webpack中的animate.css实现的执行多个连续的动画

    1.安装 npm install animate.css 2.使用方法 入口文件App中进行引入 import animate from 'animate.css' 3.多个连续的动画 实现的效果:实 ...

  7. vue 动画框架Animate.css @keyframes

    <script src="vue.js"></script> <link rel="stylesheet" href=" ...

  8. vue过渡和animate.css结合使用

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  9. 在vue中使用animate库

    <style> @keyframes bounce-in { 0% { transform: scale(0); } 50% { transform: scale(1.5) } 100% ...

随机推荐

  1. hdu 2227

    和之前的hdu3030都快一样了 可以参考之前的题解 #include <iostream> #include <cstdio> #include <cstdlib> ...

  2. jvm虚拟机---执行引擎子系统

    Java虚拟机只与Class文件相关联,它规定了Class文件应该具有的格式,而不论该文件是由什么语言编写并编译而来.所以,任何语言只要能够最终编译成符合Java虚拟机要求的Class文件,就可以运行 ...

  3. AngularJS 路由 resolve属性

    当路由切换的时候,被路由的页面中的元素(标签)就会立马显示出来,同时,数据会被准备好并呈现出来.但是注意,数据和元素并不是同步的,在没有任何设置的情况下,AngularJS默认先呈现出元素,而后再呈现 ...

  4. Delphi中break,exit,abort跳出循环的比较

    http://www.delphitop.com/html/hanshu/104.html Delphi中break,exit,abort跳出循环的比较 exit: 退出函数体abort: 遇到异常, ...

  5. Android-Kotlin-配置/入门

    1.配置Kotlin开发插件,点击File菜单,选择Settings,选择Plugins,会显示扩展的插件; 2.然后选择Browse repositories...,搜索栏目中搜索Kotlin即可, ...

  6. Weekly Contest 133

    1030. Matrix Cells in Distance Order We are given a matrix with R rows and C columns has cells with ...

  7. 《Python黑帽子:黑客与渗透测试编程之道》 自动化攻击取证

    工具安装: 下载源码:https://code.google.com/archive/p/volatility/downloads 工具配置: 获取内存镜像:https://www.downloadc ...

  8. c setjmp longjmp

    http://coolshell.cn/?s=setjmp http://www.cnblogs.com/hazir/p/c_setjmp_longjmp.html double divide(dou ...

  9. 将 Microsoft Excel 导入至 MySQL

    将 Microsoft Excel 导入至 MySQL 一.前言 我得到了一份 Microsoft Excel 表格,里面记录了数据信息需要导入至 SQL 数据库. 如果只是导入数据,当然用 MSSQ ...

  10. CentOS的ssh sftp配置及权限设置[转载-验证可用]

    从技术角度来分析,几个要求:1.从安全方面看,sftp会更安全一点2.线上服务器提供在线服务,对用户需要控制,只能让用户在自己的home目录下活动3.用户只能使用sftp,不能ssh到机器进行操作 提 ...