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;
	}

	/* 根据isAnimating的状态应用或移除旋转动画类 */
	.box.animate {
		-webkit-animation: scale-up-top 0.8s cubic-bezier(0.390, 0.575, 0.565, 1.000) both;
		animation: scale-up-top 0.8s cubic-bezier(0.390, 0.575, 0.565, 1.000) both;
	}

	/* 定义旋转动画 */
	@-webkit-keyframes scale-up-top {
		0% {
			-webkit-transform: scale(0.5);
			transform: scale(0.5);
			-webkit-transform-origin: 50% 0%;
			transform-origin: 50% 0%;
		}

		100% {
			-webkit-transform: scale(1);
			transform: scale(1);
			-webkit-transform-origin: 50% 0%;
			transform-origin: 50% 0%;
		}
	}

	@keyframes scale-up-top {
		0% {
			-webkit-transform: scale(0.5);
			transform: scale(0.5);
			-webkit-transform-origin: 50% 0%;
			transform-origin: 50% 0%;
		}

		100% {
			-webkit-transform: scale(1);
			transform: scale(1);
			-webkit-transform-origin: 50% 0%;
			transform-origin: 50% 0%;
		}
	}
</style>

教学视频地址

点击跳转教学视频

相关推荐

  1. scss基础和css扩展

    2023-12-29 01:08:05       35 阅读
  2. css连续动画动画组)

    2023-12-29 01:08:05       26 阅读
  3. css 多种动画效果

    2023-12-29 01:08:05       65 阅读
  4. CSS3——动画

    2023-12-29 01:08:05       49 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2023-12-29 01:08:05       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2023-12-29 01:08:05       106 阅读
  3. 在Django里面运行非项目文件

    2023-12-29 01:08:05       87 阅读
  4. Python语言-面向对象

    2023-12-29 01:08:05       96 阅读

热门阅读

  1. 部署UOS PXE服务器

    2023-12-29 01:08:05       42 阅读
  2. web安全,常见的攻击以及如何防御

    2023-12-29 01:08:05       55 阅读
  3. Obsidian 快捷方式总结 ——提升你的工作效率

    2023-12-29 01:08:05       91 阅读
  4. 安装Paddlehub报错

    2023-12-29 01:08:05       62 阅读
  5. c++ day3

    c++ day3

    2023-12-29 01:08:05      57 阅读
  6. MySQL-长事务详解

    2023-12-29 01:08:05       46 阅读
  7. 力扣热题100道-子串篇

    2023-12-29 01:08:05       53 阅读
  8. mysql的统计数据count

    2023-12-29 01:08:05       42 阅读
  9. C++ 657. 机器人能否返回原点 简单模拟

    2023-12-29 01:08:05       53 阅读