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-center 0.4s cubic-bezier(0.250, 0.460, 0.450, 0.940) both;
			        animation: scale-down-center 0.4s cubic-bezier(0.250, 0.460, 0.450, 0.940) both;
	}

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

</style>
相关推荐
CodingSpace5 分钟前
ESLint
前端
Csvn12 分钟前
异步错误捕获的六大陷阱:await 裹着 try-catch 就一定稳了吗?
前端
用户0595401744615 分钟前
向量库静默丢数据踩坑实录:Playwright 端到端测试让我排查了72小时
前端·css
星栈20 分钟前
SPA 写累了?试试 LiveView:服务端管状态,前端不写 JS
前端·前端框架·elixir
labixiong24 分钟前
手写Promise--微任务、静态方法、async/await 全搞懂(三)
前端·javascript
Asize29 分钟前
CSS 3D:从布局到立方体
前端
梨子同志38 分钟前
React
前端
万少1 小时前
22 点后,我靠这个 AI 工具成了"夜间天才程序员"
前端·后端
狂师1 小时前
比 Playwright 更给力,推荐一个AI Agent的浏览器自动化开源项目!
前端·开源·测试
IT_陈寒1 小时前
React hooks 闭包陷阱把我的状态吃掉了,原来问题出在这里
前端·人工智能·后端