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>
相关推荐
yuanyxh5 小时前
Mac 软件推荐
前端·javascript·程序员
万少5 小时前
AtomCode开发微信小程序《谁去呀》 全流程
前端·javascript·后端
某人辛木5 小时前
Web自动化测试
前端·python·pycharm·pytest
Kagol6 小时前
Superpowers GSD gstack AgentSkills深度测评
前端·人工智能
excel7 小时前
JavaScript 字符串与模板字面量:从表象到本质理解
前端
京东云开发者7 小时前
当AI成为导演-如何用AI创作动漫短剧
前端
李白的天不白8 小时前
使用 SmartAdmin 进行前后端开发
java·前端
乘风gg8 小时前
🤡PUA AI Coding 工具 的 10 条终极语录
前端·ai编程·claude
学Linux的语莫8 小时前
Vue 3 入门教程
前端·javascript·vue.js
怕浪猫8 小时前
第一章、Chrome DevTools Protocol (CDP) 详解
前端·javascript·chrome