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>

教学视频地址

点击跳转教学视频

相关推荐
大黄说说7 分钟前
HTML5语义化标签:从div到article与section的进化之路
前端·html·html5
帅小伙―苏8 分钟前
力扣42接雨水
前端·算法·leetcode
糯米团子74914 分钟前
react速通-2
前端·react.js·前端框架
心连欣22 分钟前
从静态页面到动态交互:DOM操作的核心API解析
前端·javascript·api
橙某人25 分钟前
SSR页面上的按钮点不了?Nuxt 懒加载水合揭秘💧
前端·vue.js·nuxt.js
PursuitofHappiness33 分钟前
2 tree-cli 的使用方法
前端
不做超级小白36 分钟前
把图片压小,但不糊:reduceUrImgs项目关键点拆解
前端·开源·node.js
耀耀切克闹灬38 分钟前
Eruda 移动端调试工具使用指南
前端
王二端茶倒水1 小时前
现在AI Agent 已经能够代替程序员的工作了,作为一个程序员的我该如何规划以后的职业,请认真思考后给我最靠谱可行的建议。
前端·后端·面试
CyrusCJA1 小时前
毛玻璃效果
前端·css·css3