当前位置: 首页 > news >正文

vue过渡及动画

文章目录

  • 前言
  • 类名
  • 使用
    • 自己定义动画样式
    • 多个元素过渡
    • 使用第三方库

前言

对于vue中的过渡与动画,官网上是这样概述的:

Vue 在插入、更新或者移除 DOM 时,提供多种不同方式的应用过渡效果。包括以下工具:

  • 在 CSS 过渡和动画中自动应用 class
  • 可以配合使用第三方 CSS 动画库,如 Animate.css
  • 在过渡钩子函数中使用 JavaScript 直接操作 DOM
  • 可以配合使用第三方 JavaScript 动画库,如 Velocity.js

简言之:vue动画就是

  1. 操作 css 的 trasition 或 animation
  2. vue 会给目标元素添加/移除特定的 class

类名

  1. xxx-enter-active: 指定显示的 transition
  2. xxx-leave-active: 指定隐藏的 transition
  3. xxx-enter/xxx-leave-to: 指定隐藏时的样式

在这里插入图片描述

使用

  1. 在目标元素外包裹
  2. 定义 class 样式
    a) 指定过渡样式: transition
    b) 指定隐藏时的样式: opacity/其它

自己定义动画样式

<template><div><button @click="isShow = !isShow">显示/隐藏</button><transition name="hello" appear><h1 v-show="isShow">你好啊!</h1></transition></div>
</template><script>export default {name:'Test',data() {return {isShow:true}},}
</script><style scoped>h1{background-color: orange;}.hello-enter-active{animation: atguigu 0.5s linear;}.hello-leave-active{animation: atguigu 0.5s linear reverse;}@keyframes atguigu {from{transform: translateX(-100%);}to{transform: translateX(0px);}}
</style>

多个元素过渡

<template><div><button @click="isShow = !isShow">显示/隐藏</button><transition-group name="hello" appear><h1 v-show="!isShow" key="1">你好啊!</h1><h1 v-show="isShow" key="2"></h1>aaa</transition-group></div>
</template><script>export default {name:'Test',data() {return {isShow:true}},}
</script><style scoped>h1{background-color: orange;}/* 进入的起点、离开的终点 */.hello-enter,.hello-leave-to{transform: translateX(-100%);}.hello-enter-active,.hello-leave-active{transition: 0.5s linear;}/* 进入的终点、离开的起点 */.hello-enter-to,.hello-leave{transform: translateX(0);}</style>

使用第三方库

<template><div><button @click="isShow = !isShow">显示/隐藏</button><transition-group appearname="animate__animated animate__bounce" enter-active-class="animate__swing"leave-active-class="animate__backOutUp"><h1 v-show="!isShow" key="1">你好啊!</h1><h1 v-show="isShow" key="2">尚硅谷!</h1></transition-group></div>
</template><script>import 'animate.css'export default {name:'Test',data() {return {isShow:true}},}
</script><style scoped>h1{background-color: orange;}</style>
http://www.lryc.cn/news/143292.html

相关文章:

  • Linux环境下SVN服务器的搭建与公网访问:使用cpolar端口映射的实现方法
  • 【ubuntu】 DNS 设置工具 resolvectl
  • Keepalived+Lvs(dr)调度器主备配置小实验
  • 第四讲Java基本语法——数组结构(多维数组)
  • 【题解】JZOJ6578 / 洛谷P5201[USACO2019Jan]Shortcut G
  • npm install sentry-cli失败的问题
  • Node opensslErrorStack 错误解决方法记录
  • 你知道什么是Grandmillennial风格吗,进来看看吧
  • App Inventor 2 开发 ChatGPT 对话App
  • SQL 大小敏感问题
  • 微信小程序+Taro 混编,Taro 使用微信原生 behaviors
  • b树/b+树、时间轮、跳表、LSM-Tree
  • Unity OnDrawGizmos的简单应用 绘制圆形
  • Uniapp笔记(四)uniapp语法3
  • leetcode做题笔记105. 从前序与中序遍历序列构造二叉树
  • Python里的列表List求和
  • 启动docker容器的几种方法和注意事项(docker-compose,dockerfile)
  • bash: conda: command not found
  • Leetcode-每日一题【剑指 Offer 36. 二叉搜索树与双向链表】
  • ctfshow-萌新专属红包题
  • 谷歌面试-扔鸡蛋
  • Unity血条制作
  • vue,uniapp生成二维码
  • 分类预测 | MATLAB实现SSA-CNN-SVM基于麻雀算法优化卷积支持向量机分类预测
  • STM32启动模式详解
  • go语言中的切片
  • HTML-常见标签、HTML5新特性
  • 微信有自己的“知乎”,微信问一问来了!
  • [MyBatis系列③]动态SQL
  • 开始MySQL之路—— DDL语法、DML语法、DQL语法基本操作详解