day86-动画与过度
使用vue写一些插入与更新或者移除dom元素时,在合适的时候使用元素动画
方法一
首先设计动画样式:
@keyframes gugu { from{ transform: translateX(-100%); } to{ transform: translateX(0px); } }
使用enter和leave设计进入与离开的动画
.hello-enter-active{ animation: gugu 1s linear; } .hello-leave-active{ animation: gugu 1s reverse; }
使用动画
<template> <div> <button @click="isShow = !isShow">显示/隐藏</button> <!-- <transition name="hello" :appear="true">--> <transition name="hello" appear> <h1 v-show="isShow">hello!</h1> </transition> </div> </template>
方法二
多个元素需要使用动画时
首先设计动画
/*进入的起点 离开的终点*/ .hello-enter,.hello-leave-to{ transform: translateX(-100%); } .hello-enter-active,.hello-leave-active{ transition: 1s linear; } /*进入的终点 离开的起点*/ .hello-enter-to,.hello-leave{ transform: translateX(0); }
使用transition-group包裹多个渲染元素
<template> <div> <button @click="isShow = !isShow">显示/隐藏</button> <!-- <transition name="hello" :appear="true">--> <transition-group name="hello" appear> <h1 v-show="isShow" key="1">hello!</h1> <h1 v-show="isShow" key="2">gugu!</h1> </transition-group> </div> </template>
方法三
引入snimate.css包使用现成动画
import 'animate.css'
在dom元素上设计动画,有一些固定的格式
<template> <div> <!-- <button @click="isShow = !isShow">显示/隐藏</button>--> <!-- <transition name="hello" :appear="true">--> <transition-group name="animate__animated animate__bounce" appear enter-active-class="animate__rubberBand" leave-active-class="animate__backOutUp" > <h1 v-show="isShow" key="2">hello!</h1> </transition-group> <transition name="animate__animated animate__bounce" appear enter-active-class="animate__heartBeat" leave-active-class="" > <h1 v-show="isShow" key="2">beautiful girl cmt</h1> </transition> </div> </template>
总结
/* vue封装的过度与动画 1.作用:在插入,更新或移除dom元素时,在合适的时候给元素添加样式类名 2.写法: 1.准备好样式: 元素进入的样式: v-enter:进入的起点 v-enter-active:进入过程中 v-enter-to:进入的终点 元素离开的样式: v-leave:离开的起点 v-leave-active:离开过程中 v-leave-to:离开的终点 2.使用<transition>包裹要过度的元素,并配置name属性 <transition name="hello" appear> <h1 v-show="isShow">hello!</h1> </transition> 3.若有多个元素需要过度,则需要使用<transition-group> 且每个元素需要指定key值 */
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· AI Agent开发,如何调用三方的API Function,是通过提示词来发起调用的吗