Vue3新组件transition(动画过渡)

news/2024/9/23 4:41:43/

transition组件:控制V-if与V-show的显示与隐藏动画

1.基本使用 

 

<template><div><button @click="falg = !falg">切换</button><transition name="fade" :enter-to-class="etc"><div v-if="falg" class="box ">box1</div><div v-else class="box2">box2</div></transition></div>
</template>
javascript"><script>
const falg = ref(true)
</script>

 样式动画

<style scoped>
.box {width: 200px;height: 200px;text-align: center;background-color: red;line-height: 200px;}.box2 {text-align: center;line-height: 200px;width: 200px;height: 200px;color: white;background-color: black;
}
/* 插入的新元素初始的样式 */
.fade-enter-from {width: 0;height: 0;color: white;
}.fade-enter-active,
.fade-leave-active {transition: all 5s ease;
}/* 出入的新的元素的结束的样式 */
.fade-enter-to {width: 200px;height: 200px;transform: translateY(-200px);/* background: black; */
}
/* 移除旧元素的结束的样式 */
.fade-leave-to {width: 200px;height: 200px;background: white;
}
</style>

2.appear属性

在进入页面时就会触发enter-from到enter-to的动画

<template><div><button @click="falg = !falg">切换</button><transition appear name="fade" :enter-to-class="etc"><div v-if="falg" class="box ">box1</div><div v-else class="box2">box2</div></transition></div>
</template>

3.小案例-按钮切换滚动

<script setup>
import { ref } from 'vue'const docState = ref('saved')
</script><template><span style="margin-right: 20px">Click to cycle through states:</span><div class="btn-container"><Transition name="slide-up"><button v-if="docState === 'saved'"@click="docState = 'edited'">Edit</button><button v-else-if="docState === 'edited'"@click="docState = 'editing'">Save</button><button v-else-if="docState === 'editing'"@click="docState = 'saved'">Cancel</button></Transition></div>
</template><style>
.btn-container {display: inline-block;position: relative;height: 1em;
}button {position: absolute;
}.slide-up-enter-active,
.slide-up-leave-active {transition: all 0.25s ease-out;
}.slide-up-enter-from {opacity: 0;transform: translateY(30px);
}.slide-up-leave-to {opacity: 0;transform: translateY(-30px);
}
</style>

4.配合animate.css动画库使用

4.1下载安装animate依赖包

npm install animate.css -S
javascript">yarn add animate.css -S

 

 4.2在使用的组件中导入

javascript">import 'animate.css';

 4.3结合transition使用animate动画库

<script setup>
import 'animate.css';
const falg = ref(true)
</script>
<template><div style="margin-top: 500px;"><button @click="falg = !falg">切换</button><transition name="fade" :enter-to-class="etc"><h1 v-if="falg"><div class="box animate__animated animate__bounce">你好</div></h1><h1 v-else><div class="box2 animate__animated animate__fadeInLeft">你好</div></h1></transition></div><div class="box2 animate__animated animate__hinge">你好</div>
</template>
<style scoped>
.box {width: 200px;height: 200px;text-align: center;background-color: red;line-height: 200px;}.box2 {text-align: center;line-height: 200px;width: 200px;height: 200px;color: white;background-color: black;
}</style>

 


http://www.ppmy.cn/news/1529154.html

相关文章

shopro前端 短信登录只显示模板不能正常切换

删掉 换成下面的代码 // 打开授权弹框 export function showAuthModal(type smsLogin) {const modal $store(modal);setTimeout(() > {modal.$patch((state) > {state.auth type;});}, 100); }

tensorflow算子调用示例(MINIST)

tensorflow算子调用示例(MINIST) 本文以MINIST为例&#xff0c;阐述在模型训练时&#xff0c;tensorflow框架每个算子具体调用kernel的过程。 1. 数据准备和输入 在 MNIST 示例中&#xff0c;首先加载数据并进行预处理&#xff0c;生成用于训练和测试的数据集。这个步骤本身…

Python知识点:如何使用Python进行智能合约开发(Solidity、Web3.py)

开篇&#xff0c;先说一个好消息&#xff0c;截止到2025年1月1日前&#xff0c;翻到文末找到我&#xff0c;赠送定制版的开题报告和任务书&#xff0c;先到先得&#xff01;过期不候&#xff01; 要使用Python进行智能合约开发&#xff0c;你需要了解Solidity语言和Web3.py库。…

数据湖 Data Lake-概述

Data Lake 1. 数据湖的定义 数据湖是一种存储系统&#xff0c;用于集中存储大量的原始数据&#xff0c;可以按数据本来的原始格式进行存储&#xff0c;用户可以在需要时提取和分析这些数据。 A data lake is a centralized repository designed to hold vast volumes of data …

Kubernetes从零到精通(11-CNI网络插件)

Kubernetes网络模型 Kubernetes的网络模型&#xff08;Kubernetes Networking Model&#xff09;旨在提供跨所有节点、Pod和服务的统一网络连接。它的核心理念是通过统一的网络通信规则&#xff0c;保证集群中的所有组件能够顺畅地相互通信。Kubernetes网络模型主要有以下几个关…

网络编程问题解答

TCP/IP是哪种模型的协议 TCP/IP 是一组通信协议的集合&#xff0c;它基于 TCP/IP 模型。TCP/IP 模型通常被认为是一种实用的网络通信模型&#xff0c;与 OSI 模型相比&#xff0c;TCP/IP 模型更加简洁和侧重于实际应用&#xff0c;被广泛应用于互联网和大多数计算机网络中。 T…

React学习day07-ReactRouter-抽象路由模块、路由导航、路由导航传参、嵌套路由、默认二级路由的设置、两种路由模式

14、ReactRouter续 &#xff08;2&#xff09;抽象路由模块 1&#xff09;新建page文件夹&#xff0c;存放组件 组件内容&#xff1a; 2&#xff09;新建router文件夹&#xff0c;在其下创建实例 3&#xff09;实例导入&#xff0c;使用 4&#xff09;效果 &#xff08;3&…

PG198-jesd204-phy阅读笔记

JESD204B接口学习资料收集 简介 介绍 JESD204 PHY IP核实现了JESD204的物理接口&#xff0c;简化在发送和接收核心之间共享串行收发器信息通道。此内核一般不单独使用&#xff0c;只能与JESD204或JESD204C内核结合使用。 特性 根据JESD204B和JESD204C草案设计   支持1至12…