纯CSS实现117款常用的loading等待加载效果
圆圈加载L1
可以直接查看全部案例:http://code.wubin.work/code/css/css-loading/
<div class="com__box">
<!-- loading -->
<div class="loading"></div>
</div>
.loading {
width: 30px;
height: 30px;
border: 2px solid #000;
border-top-color: transparent;
border-radius: 100%;
animation: circle infinite 0.75s linear;
}
@keyframes circle {
0% {
transform: rotate(0);
}
100% {
transform: rotate(360deg);
}
}
等待点点点L112
<div class="com__box">
<!-- loading -->
<div class="loading">Loading</div>
</div>
.loading {
display: inline-block;
color: #ddd;
position: relative;
font-size: 28px;
font-family: Arial, Helvetica, sans-serif;
}
.loading::after {
content: "";
width: 3px;
height: 3px;
background: currentColor;
position: absolute;
bottom: 6px;
right: -5px;
animation: loading-animation 1s linear infinite;
}
@keyframes loading-animation {
0% {
box-shadow: 10px 0 rgba(255, 255, 255, 0), 20px 0 rgba(255, 255, 255, 0);
}
50% {
box-shadow: 10px 0 #ddd, 20px 0 rgba(255, 255, 255, 0);
}
100% {
box-shadow: 10px 0 #ddd, 20px 0 #ddd;
}
}
转圈圈L2
<div class="com__box">
<!-- loading -->
<div class="loading"></div>
</div>
.loading {
position: relative;
width: 30px;
height: 30px;
border: 2px solid #000;
border-top-color: rgba(0, 0, 0, 0.2);
border-right-color: rgba(0, 0, 0, 0.2);
border-bottom-color: rgba(0, 0, 0, 0.2);
border-radius: 100%;
animation: circle infinite 0.75s linear;
}
@keyframes circle {
0% {
transform: rotate(0);
}
100% {
transform: rotate(360deg);
}
}
点转圈L34
<div class="com__box">
<!-- loading -->
<div class="loading">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
</div>
.loading,
.loading > div {
position: relative;
box-sizing: border-box;
}
.loading {
display: block;
font-size: 0;
color: #000;
}
.loading.la-dark {
color: #333;
}
.loading > div {
display: inline-block;
float: none;
background-color: currentColor;
border: 0 solid currentColor;
}
.loading {
width: 32px;
height: 32px;
}
.loading > div {
position: absolute;
top: 50%;
left: 50%;
width: 8px;
height: 8px;
margin-top: -4px;
margin-left: -4px;
border-radius: 100%;
animation: ball-spin-clockwise 1s infinite ease-in-out;
}
.loading > div:nth-child(1) {
top: 5%;
left: 50%;
animation-delay: -0.875s;
}
.loading > div:nth-child(2) {
top: 18.1801948466%;
left: 81.8198051534%;
animation-delay: -0.75s;
}
.loading > div:nth-child(3) {
top: 50%;
left: 95%;
animation-delay: -0.625s;
}
.loading > div:nth-child(4) {
top: 81.8198051534%;
left: 81.8198051534%;
animation-delay: -0.5s;
}
.loading > div:nth-child(5) {
top: 94.9999999966%;
left: 50.0000000005%;
animation-delay: -0.375s;
}
.loading > div:nth-child(6) {
top: 81.8198046966%;
left: 18.1801949248%;
animation-delay: -0.25s;
}
.loading > div:nth-child(7) {
top: 49.9999750815%;
left: 5.0000051215%;
animation-delay: -0.125s;
}
.loading > div:nth-child(8) {
top: 18.179464974%;
left: 18.1803700518%;
animation-delay: 0s;
}
.loading.la-sm {
width: 16px;
height: 16px;
}
.loading.la-sm > div {
width: 4px;
height: 4px;
margin-top: -2px;
margin-left: -2px;
}
.loading.la-2x {
width: 64px;
height: 64px;
}
.loading.la-2x > div {
width: 16px;
height: 16px;
margin-top: -8px;
margin-left: -8px;
}
.loading.la-3x {
width: 96px;
height: 96px;
}
.loading.la-3x > div {
width: 24px;
height: 24px;
margin-top: -12px;
margin-left: -12px;
}
@keyframes ball-spin-clockwise {
0%,
100% {
opacity: 1;
transform: scale(1);
}
20% {
opacity: 1;
}
80% {
opacity: 0;
transform: scale(0);
}
}
使用base64图片背景作为加载
// 图片base64
data:image/gif;base64,R0lGODlhHgAeAMQZAN3d3bu7u5qamt7e3ry8vNzc3Lq6upiYmJubm5eXl5aWltvb29ra2ri4uJGRkeDg4Lm5ub6+vr29vd/f35WVlZKSkpycnP///5mZmQAAAAAAAAAAAAAAAAAAAAAAAAAAACH/C05FVFNDQVBFMi4wAwEAAAAh/wtYTVAgRGF0YVhNUDw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0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InWipjgKarnAszypBr0Rwl1Dg7yTfT5RQLQCD0pB0uYwAgJhg1CRBadVndJbVcp3WbawLzIBpIQAh+QQFBQAZACwGAA8AFgAPAAAFRGAmjmQpYmaqrmzrZmgpHK8Qi/ObJVivmz3f6HIxQQKEkjBDHBUAo0BgRSyKANDoNNUcYUlSbvea1XJLX/C2lf6RyqsQACH5BAUFABkALAMADwAUAA8AAAVAYCZajmieaKqubIternrNcYZlM11jeX3CqAEglcDcVEKTIWAyIgFDUYDZPJ6gp+nJecWatFurKPqlVl1g31cVAgAh+QQFBQAZACwAAAoAEwAUAAAFQGAmisJonqioIGnrvrB5zXRM31es77zI9BmAcCcc6oo9AIoQQGFczNHh+WI2RRiqK3DFalPcbiYLE4+/OjJQGwIAIfkEBQUAGQAsAAAFAA8AFwAABT5gJo4iQp6oiWZXil5wO1bCGq/vjZPw7v8rgHCIGw4LD6ByeWooA1AfNLqbAgMoAQaoHW1X2q8PI96Ry2ZUCAAh+QQJBQAZACwAAAIADwAXAAAFPmAmjuJFnuRloqzKour6jq4ojAAsi0Cf0ztcb0by/YiZwRHJRAae0BcUaog0r1iRoonpErveGZiJQZXJXFQIADs=
// 使用
.loading-bg{
background-image: url('data:image/gif;base64,R...');
background-repeat: no-repeat;
background-position: center center;
}