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>
相关推荐
问心无愧05134 小时前
ctf show web入门160 161
前端·笔记
李小白664 小时前
第四天-WEB服务器基本原理,IIS服务
运维·服务器·前端
humcomm5 小时前
AI编程时代新前端职位
前端·ai编程
好家伙VCC5 小时前
Web Components主题热切换方案揭秘
java·前端
甲维斯5 小时前
Kimi版超级玛丽效果“惊人”,配额不足5厘米!
前端·人工智能
hboot6 小时前
AI工程师第一课 - Python
前端·后端·python
凉菜凉凉6 小时前
AI时代,被抛弃的前端
前端·ai
console.log('npc')6 小时前
AI前端工程与生成式UI学习路线
前端·人工智能·ui
梦曦i6 小时前
uni-router v1.1.1发布:守卫超时保护+路由监听
前端·uni-app
qq_2518364576 小时前
基于java Web网络订餐系统设计与实现 源码文档
java·开发语言·前端