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>
相关推荐
码事漫谈2 分钟前
在 Kubernetes 上管好数据库:金仓 KES-Operator 正式落地
前端·后端
用户1880687493528 分钟前
手上全是油,我怎么让rokid眼镜在厨房里教我炒菜
前端
gnip10 分钟前
uni-app 原生插件
前端·javascript·uni-app
gnip18 分钟前
跨域常用解决方案
前端·javascript
用户2986985301425 分钟前
前端如何把 TXT 文本文件转成 Word 文档:React 实践
前端·javascript·react.js
FEF前端团队25 分钟前
03# Claude Code实战:终端里的逻辑引擎
前端·ai编程·claude
FEF前端团队29 分钟前
04# Codex CLI实战:OpenAI的编程代理
前端·chatgpt·ai编程
掘金挖土31 分钟前
前端手摸手跑路之 AI 应用开发(七)
前端·后端
data analyse 45632 分钟前
重复事件怎么去重:按请求ID、用户+时间窗还是会话聚合?
前端·数据分析
亿元程序员32 分钟前
让Codex直接生成PSD难吗?提示词其实很简单
前端