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-up-tr 0.4s cubic-bezier(0.390, 0.575, 0.565, 1.000) both;
			        animation: scale-up-tr 0.4s cubic-bezier(0.390, 0.575, 0.565, 1.000) both;
	}

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

</style>

教学视频地址

点击跳转教学视频

相关推荐
_请输入用户名5 分钟前
EventEmitter 是广播,Tapable 是流水线:聊聊它们的本质区别
前端·设计模式
爱学习的茄子6 分钟前
React Fiber:让大型应用告别卡顿的性能革命
前端·react.js·面试
龙在天7 分钟前
我是前端,我来总结一下前端 配 Nginx 的一些案例
前端
Thetimezipsby10 分钟前
基于Taro4打造的一款最新版微信小程序、H5的多端开发简单模板
前端·javascript·微信小程序·typescript·html5·taro
掘金安东尼21 分钟前
前端周刊430期(2025年9月1日–9月7日)
前端
BUG创建者28 分钟前
uni 拍照上传拍视频上传以及相册
前端·javascript·音视频
就是帅我不改35 分钟前
敏感词过滤黑科技!SpringBoot+Vue3+TS强强联手,打造无懈可击的内容安全防线
前端·vue.js·后端
JackJiang35 分钟前
转转客服IM系统的WebSocket集群架构设计和部署方案
前端
codeGoogle36 分钟前
大厂研发之谜:千亿投入砸出利润大缩水
前端·人工智能·后端
菲兹园长1 小时前
CSS(展示效果)
前端·javascript·css