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>

教学视频地址

点击跳转教学视频

相关推荐
Sailing11 小时前
🚀 别再乱写 16px 了!CSS 单位体系已经进入“计算时代”,真正的响应式布局
前端·css·面试
喝水的长颈鹿11 小时前
【大白话前端 03】Web 标准与最佳实践
前端
爱泡脚的鸡腿11 小时前
Node.js 拓展
前端·后端
左夕12 小时前
分不清apply,bind,call?看这篇文章就够了
前端·javascript
Zha0Zhun13 小时前
一个使用ViewBinding封装的Dialog
前端
兆子龙13 小时前
从微信小程序 data-id 到 React 列表性能优化:少用闭包,多用 data-*
前端
滕青山13 小时前
文本行过滤/筛选 在线工具核心JS实现
前端·javascript·vue.js
时光不负努力13 小时前
编程常用模式集合
前端·javascript·typescript
恋猫de小郭13 小时前
Apple 的 ANE 被挖掘,AI 硬件公开,宣传的 38 TOPS 居然是"数字游戏"?
前端·人工智能·ios
小岛前端13 小时前
Node.js 宣布重大调整,运行十年的规则要改了!
前端·node.js