css圆环加载效果,两种效果

本文介绍两种在H5页面中实现加载动画的方法,一种通过元素的缩放变化,另一种利用透明度变化,以实现视觉上的旋转加载效果。

场景:在H5页面发送请求或者是其他需要反馈操作的时候,出来的加载效果。之前使用的时候图片,但是在适配的时候,图片的效果比较差,所以就手动写了两种效果。

第一种

代码

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Dot1</title>
	<style type="text/css">
		* {
			margin: 0;
			padding: 0
		}
		body {
			margin: 0;
			height: 100vh;
			display: flex;
			align-items: center;
			justify-content: center;
			background-color: #EEE;
		}
		.box {
			width: 4em;
			height: 4em;
			position: relative;
			margin: auto;
		}

		.box .dots {
			width: 100%;
			height: 100%;
			position: absolute;
			left: 0;
			top: 0;
		}

		.box .dots:before {
			content: '';
			display: block;
			margin: 0 auto;
			width: 15%;
			height: 15%;
			background-color: #00BFFF;
			border-radius: 50%;
			animation: animate 1.2s infinite ease-in-out both;
		}

		.box .childDots2 {
			transform: rotate(30deg);
		}

		.box .childDots3 {
			transform: rotate(60deg);
		}

		.box .childDots4 {
			transform: rotate(90deg);
		}

		.box .childDots5 {
			transform: rotate(120deg);
		}

		.box .childDots6 {
			transform: rotate(150deg);
		}

		.box .childDots7 {
			transform: rotate(180deg);
		}

		.box .childDots8 {
			transform: rotate(210deg);
		}

		.box .childDots9 {
			transform: rotate(240deg);
		}

		.box .childDots10 {
			transform: rotate(270deg);
		}

		.box .childDots11 {
			transform: rotate(300deg);
		}

		.box .childDots12 {
			transform: rotate(330deg);
		}

		.box .childDots2:before {
			animation-delay: -1.1s;
		}

		.box .childDots3:before {
			animation-delay: -1s;
		}

		.box .childDots4:before {
			animation-delay: -0.9s;
		}

		.box .childDots5:before {
			animation-delay: -0.8s;
		}

		.box .childDots6:before {
			animation-delay: -0.7s;
		}

		.box .childDots7:before {
			animation-delay: -0.6s;
		}

		.box .childDots8:before {
			animation-delay: -0.5s;
		}

		.box .childDots9:before {
			animation-delay: -0.4s;
		}

		.box .childDots10:before {
			animation-delay: -0.3s;
		}

		.box .childDots11:before {
			animation-delay: -0.2s;
		}

		.box .childDots12:before {
			animation-delay: -0.1s;
		}

		@-webkit-keyframes animate {

			0%,
			80%,
			100% {
				transform: scale(0);
			}

			40% {
				transform: scale(1);
			}
		}

		@keyframes animate {

			0%,
			80%,
			100% {
				transform: scale(0);
			}

			40% {
				transform: scale(1);
			}
		}
	</style>
</head>
<body>
	<div class='box'>
		<div class='dots childDots1'></div>
		<div class='dots childDots2'></div>
		<div class='dots childDots3'></div>
		<div class='dots childDots4'></div>
		<div class='dots childDots5'></div>
		<div class='dots childDots6'></div>
		<div class='dots childDots7'></div>
		<div class='dots childDots8'></div>
		<div class='dots childDots9'></div>
		<div class='dots childDots10'></div>
		<div class='dots childDots11'></div>
		<div class='dots childDots12'></div>
	</div>
</body>
</html>

效果
在这里插入图片描述

第二种

代码


<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Dot2</title>
	<style type="text/css">
		* {
			margin: 0;
			padding: 0
		}
		body {
			margin: 0;
			height: 100vh;
			display: flex;
			align-items: center;
			justify-content: center;
			background-color: #EEE;
		}
		.box {
			position: relative;
			margin: auto;
			width: 4em;
			height: 4em;					
		}

		.box .dots {
			position: absolute;
			left: 0;
			top: 0;
			width: 100%;
			height: 100%;			
		}

		.box .dots:before {
			content: '';
			display: block;
			margin: 0 auto;
			width: 15%;
			height: 15%;
			background-color: #00BFFF;
			border-radius: 50%;			
			animation: animate 1.2s infinite ease-in-out both;
		}

		.box .childDots2 {
			transform: rotate(30deg);
		}

		.box .childDots3 {
			transform: rotate(60deg);
		}

		.box .childDots4 {
			transform: rotate(90deg);
		}

		.box .childDots5 {
			transform: rotate(120deg);
		}

		.box .childDots6 {
			transform: rotate(150deg);
		}

		.box .childDots7 {
			transform: rotate(180deg);
		}

		.box .childDots8 {
			transform: rotate(210deg);
		}

		.box .childDots9 {
			transform: rotate(240deg);
		}

		.box .childDots10 {
			transform: rotate(270deg);
		}

		.box .childDots11 {
			transform: rotate(300deg);
		}

		.box .childDots12 {
			transform: rotate(330deg);
		}

		.box .childDots2:before {
			animation-delay: -1.1s;
		}

		.box .childDots3:before {
			animation-delay: -1s;
		}

		.box .childDots4:before {
			animation-delay: -0.9s;
		}

		.box .childDots5:before {
			animation-delay: -0.8s;
		}

		.box .childDots6:before {
			animation-delay: -0.7s;
		}

		.box .childDots7:before {
			animation-delay: -0.6s;
		}

		.box .childDots8:before {
			animation-delay: -0.5s;
		}

		.box .childDots9:before {
			animation-delay: -0.4s;
		}

		.box .childDots10:before {
			animation-delay: -0.3s;
		}

		.box .childDots11:before {
			animation-delay: -0.2s;
		}

		.box .childDots12:before {
			animation-delay: -0.1s;
		}

		@-webkit-keyframes animate {

			0%,
			39%,
			100% {
				opacity: 0;
			}

			40% {
				opacity: 1;
			}
		}

		@keyframes animate {

			0%,
			39%,
			100% {
				opacity: 0;
			}

			40% {
				opacity: 1;
			}
		}
	</style>
</head>
<body>
	<div class='box'>
		<div class='dots childDots1'></div>
		<div class='dots childDots2'></div>
		<div class='dots childDots3'></div>
		<div class='dots childDots4'></div>
		<div class='dots childDots5'></div>
		<div class='dots childDots6'></div>
		<div class='dots childDots7'></div>
		<div class='dots childDots8'></div>
		<div class='dots childDots9'></div>
		<div class='dots childDots10'></div>
		<div class='dots childDots11'></div>
		<div class='dots childDots12'></div>
	</div>
</body>
</html>

效果
在这里插入图片描述

总结

上面两种写法都是比较“蠢”的写法。都是在一开始就把所有的画好,让它们围成一个圆。然后通过改变css 的属性来达到视觉上的旋转加载的效果。第一种是通过放大缩小;第二种是使用透明度。
也可以通过只写几个固定的小圆点,在将大小或者透明度设置好,然后整体旋转Box 这个div来真正的“旋转”。

当然也有更多的写法,这两种就是最简单的把我的思路写出来,没有再去进一步修改。

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

余九月丶

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值