CSS 缩减顶部动画

复制代码
<template>
	<!-- @mouseenter="startAnimation" 表示在鼠标进入元素时触发 startAnimation 方法。
	@mouseleave="stopAnimation" 表示在鼠标离开元素时触发 stopAnimation 方法。 -->
	<!-- 容器元素 -->
	<div class="container" @mouseenter="startAnimation" @mouseleave="stopAnimation">
		<!-- 方块 -->
		<div class="box" :class="{ 'animate': isAnimating }">
			<!-- 元素内容 -->
		</div>
	</div>
</template>
<script setup>
	import {
		ref
	} from 'vue';


	const isAnimating = ref(false); // 控制是否应用动画的响应式状态
	function startAnimation() {
		// 鼠标进入容器时,启动动画
		isAnimating.value = true;
	}

	function stopAnimation() {
		// 鼠标离开容器时,停止动画
		isAnimating.value = false;
	}
</script>
<style>
	.container {
		/* 定义容器宽度和高度 */
		width: 100px;
		height: 100px;
		margin-top: 50px;
		margin-left: 40%;
	}

	.box {
		/* 定义方块宽度和高度 */
		width: 100px;
		height: 100px;
		background-color: blue;
		/* 定义过渡效果 */
		transition: transform 0.5s;
	}

	/* 应用动画类 */
	.box.animate {
	-webkit-animation: scale-down-top 0.4s cubic-bezier(0.250, 0.460, 0.450, 0.940) both;
		        animation: scale-down-top 0.4s cubic-bezier(0.250, 0.460, 0.450, 0.940) both;
	}

	/* 定义动画 */
	@-webkit-keyframes scale-down-top {
	  0% {
	    -webkit-transform: scale(1);
	            transform: scale(1);
	    -webkit-transform-origin: 50% 0%;
	            transform-origin: 50% 0%;
	  }
	  100% {
	    -webkit-transform: scale(0.5);
	            transform: scale(0.5);
	    -webkit-transform-origin: 50% 0%;
	            transform-origin: 50% 0%;
	  }
	}
	@keyframes scale-down-top {
	  0% {
	    -webkit-transform: scale(1);
	            transform: scale(1);
	    -webkit-transform-origin: 50% 0%;
	            transform-origin: 50% 0%;
	  }
	  100% {
	    -webkit-transform: scale(0.5);
	            transform: scale(0.5);
	    -webkit-transform-origin: 50% 0%;
	            transform-origin: 50% 0%;
	  }
	}

</style>

### 教学视频地址

点击跳转教学视频(https://edu.csdn.net/course/detail/39132)

相关推荐
云和数据.ChenGuang3 分钟前
光哥说Python 循环导入(Circular Import)深度解析:成因、排查与解决方案
开发语言·前端·人工智能·python·langchain
avi91116 分钟前
【AI教人】在Inspector显示所有Delegate-Odin Inspector之三
java·前端·算法·delegate·inspector·editor扩展·unity editor
fengci.18 分钟前
BUUCTF(困难部分)
android·开发语言·前端·学习·php
Ward的AI产品实战19 分钟前
开源 AI 网关 Magpie 调优终结篇:顺位排错、跨家族对抗审查与 5 大路由组重构(下篇)
前端·人工智能
Highcharts.js22 分钟前
BI可视化图表“维护难”问题的解决方案
开发语言·前端·javascript·编辑器·ecmascript·bi·highcharts
广州华水科技35 分钟前
单北斗GNSS在建筑形变监测中的应用与优势分析
前端
hunter_07641 分钟前
Swift、Objective-C++ 与 Flutter 如何调用 C++:从混编接入到内存安全
前端
Java后端的Ai之路1 小时前
前端技术Vue-13-安装webpack与vuejs
前端·vue.js·webpack
倚窗听花_1 小时前
IIS部署前端Vue项目
前端·javascript·vue.js
yixun_gdas1 小时前
政企网站错敏巡查:错敏都藏在哪些位置?
开发语言·前端·javascript·内容运营