css 实现心形加载动画


前言

心形加载动画
在这里插入图片描述


提示:以下是本篇文章的代码内容,供大家参考,相互学习

一、html代码

代码如下:

<html>
	<head>
		<meta http-equiv="content-type" content="text/html; charset=utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">

		<title></title>
	</head>

	<body>
		<div class="container">
			<div class="loading">
				<span></span>
				<span></span>
				<span></span>
			</div>
			<div class="shadow"></div>
		</div>
	</body>

</html>

二、css

代码如下:

* {
				/* 初始化 */
				margin: 0;
				padding: 0;
			}

			body {
				/* 100%窗口高度 */
				height: 100vh;
				/* 弹性布局 居中 */
				display: flex;
				justify-content: center;
				align-items: center;
			}

			.container {
				/* 绝对定位 */
				position: absolute;
				top: 40vh;
			}

			.loading {
				/* 执行动画:动画名 时长 贝塞尔曲线 无限次播放 */
				animation: rotate 2.5s cubic-bezier(0.75, 0, 0.5, 1) infinite;
			}

			.loading span {
				width: 100px;
				height: 100px;
				display: block;
				position: absolute;
				background-color: #ff8f92;
				border: 1px solid #ff8f92;
				border-radius: 100%;
			}

			.loading span:nth-child(1) {
				transform: translate(-28px, -28px);
				/* 执行动画:动画名 时长 贝塞尔曲线 无限次播放 */
				animation: animate1 2.5s cubic-bezier(0.75, 0, 0.5, 1) infinite;
			}

			.loading span:nth-child(2) {
				transform: translate(28px, -28px);
				/* 执行动画:动画名 时长 贝塞尔曲线 无限次播放 */
				animation: animate2 2.5s cubic-bezier(0.75, 0, 0.5, 1) infinite;
			}

			.loading span:nth-child(3) {
				position: relative;
				border-radius: 0;
				transform: scale(0.98) rotate(-45deg);
				/* 执行动画:动画名 时长 贝塞尔曲线 无限次播放 */
				animation: animate3 2.5s cubic-bezier(0.75, 0, 0.5, 1) infinite;
			}

			/* 阴影部分 */
			.shadow {
				position: relative;
				width: 100px;
				height: 20px;
				background-color: #d9d9d9;
				border-radius: 50%;
				top: 50px;
				animation: shadow 2.5s cubic-bezier(0.75, 0, 0.5, 1) infinite;
			}

			/* 定义动画 */
			/* 心形 左圆 */
			@keyframes animate1 {
				60% {
					transform: scale(0.4);
				}
			}

			/* 心形 右圆 */
			@keyframes animate2 {
				40% {
					transform: scale(0.4);
				}
			}

			/* 心形 中间部分 */
			@keyframes animate3 {
				50% {
					border-radius: 100%;
					transform: scale(0.5) rotate(-45deg);
				}

				100% {
					transform: scale(0.98) rotate(-45deg);
				}
			}

			/* 再加个心形整体的旋转动画 */
			@keyframes rotate {
				50% {
					transform: rotate(360deg);
				}

				100% {
					transform: rotate(720deg);
				}
			}

			/* 阴影动画 */
			@keyframes shadow {
				50% {
					background-color: #f2f2f2;
					transform: scale(0.5);
				}
			}

总结

  1. 使用动画设置阴影变化 animation: shadow 2.5s cubic-bezier(0.75, 0, 0.5, 1) infinite;
  2. 三个span形成组成形状,通过动画改变
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值