今天给大家带来一个很酷的 CSS3 加载动画。它的特别之处在于,整个动画呈现出一种3D的视觉效果。这个加载动画由 12 个 3D 圆柱体包围一个椭圆组成,这 12 个圆柱体依次起伏,从而向用户传达“加载”的信息。
效果预览
代码实现
HTML 代码
HTML代码很简单,对象分为三种,一种是最外层的椭圆容器,一种是12个圆柱体,最后一种是“”文字。
Loading…
CSS 代码
CSS代码主要做了三件事:
首先是让最外层的椭圆容器呈现一个内嵌的3D视觉效果,这里用box-:
<code class="language-css">.pl { box-shadow: 2em 0 2em rgba(0, 0, 0, 0.2) inset, -2em 0 2em rgba(255, 255, 255, 0.1) inset; display: flex; justify-content: center; align-items: center; position: relative; letter-spacing: 0.1em; text-transform: uppercase; transform: rotateX(30deg) rotateZ(45deg); width: 15em; height: 15em; }
然后让12个元素
为了变成一个有3D效果的小圆圈,这里主要使用box-and-:
.pl__dot {
border-radius: 50%;
}
.pl__dot {
animation-name: shadow;
box-shadow: 0.1em 0.1em 0 0.1em black, 0.3em 0 0.3em rgba(0, 0, 0, 0.5);
top: calc(50% - 0.75em);
left: calc(50% - 0.75em);
width: 1.5em;
height: 1.5em;
}
.pl__dot, .pl__dot:before, .pl__dot:after {
animation-duration: 2s;
animation-iteration-count: infinite;
position: absolute;
}
.pl__dot:before, .pl__dot:after {
content: "";
display: block;
left: 0;
width: inherit;
transition: background-color var(--trans-dur);
}
.pl__dot:before {
animation-name: pushInOut1;
background-color: var(--bg);
border-radius: inherit;
box-shadow: 0.05em 0 0.1em rgba(255, 255, 255, 0.2) inset;
height: inherit;
z-index: 1;
}
.pl__dot:after {
animation-name: pushInOut2;
background-color: var(--primary1);
border-radius: 0.75em;
box-shadow: 0.1em 0.3em 0.2em rgba(255, 255, 255, 0.4) inset, 0 -0.4em 0.2em #2e3138 inset, 0 -1em 0.25em rgba(0, 0, 0, 0.3) inset;
bottom: 0;
clip-path: polygon(0 75%, 100% 75%, 100% 100%, 0 100%);
height: 3em;
transform: rotate(-45deg);
transform-origin: 50% 2.25em;
}
最后一步是让12个小圆圈以不同的时间间隔旋转不同的角度,从而形成波浪状的起伏效果。
.pl__dot:nth-child(1) {
transform: rotate(0deg) translateX(5em) rotate(0deg);
z-index: 5;
}
.pl__dot:nth-child(1), .pl__dot:nth-child(1):before, .pl__dot:nth-child(1):after {
animation-delay: 0s;
}
.pl__dot:nth-child(2) {
transform: rotate(-30deg) translateX(5em) rotate(30deg);
z-index: 4;
}
.pl__dot:nth-child(2), .pl__dot:nth-child(2):before, .pl__dot:nth-child(2):after {
animation-delay: -0.1666666667s;
}
.pl__dot:nth-child(3) {
transform: rotate(-60deg) translateX(5em) rotate(60deg);
z-index: 3;
}
.pl__dot:nth-child(3), .pl__dot:nth-child(3):before, .pl__dot:nth-child(3):after {
animation-delay: -0.3333333333s;
}
.pl__dot:nth-child(4) {
transform: rotate(-90deg) translateX(5em) rotate(90deg);
z-index: 2;
}
.pl__dot:nth-child(4), .pl__dot:nth-child(4):before, .pl__dot:nth-child(4):after {
animation-delay: -0.5s;
}
.pl__dot:nth-child(5) {
transform: rotate(-120deg) translateX(5em) rotate(120deg);
z-index: 1;
}
.pl__dot:nth-child(5), .pl__dot:nth-child(5):before, .pl__dot:nth-child(5):after {
animation-delay: -0.6666666667s;
}
.pl__dot:nth-child(6) {
transform: rotate(-150deg) translateX(5em) rotate(150deg);
z-index: 1;
}
.pl__dot:nth-child(6), .pl__dot:nth-child(6):before, .pl__dot:nth-child(6):after {
animation-delay: -0.8333333333s;
}
.pl__dot:nth-child(7) {
transform: rotate(-180deg) translateX(5em) rotate(180deg);
z-index: 2;
}
.pl__dot:nth-child(7), .pl__dot:nth-child(7):before, .pl__dot:nth-child(7):after {
animation-delay: -1s;
}
.pl__dot:nth-child(8) {
transform: rotate(-210deg) translateX(5em) rotate(210deg);
z-index: 3;
}
.pl__dot:nth-child(8), .pl__dot:nth-child(8):before, .pl__dot:nth-child(8):after {
animation-delay: -1.1666666667s;
}
.pl__dot:nth-child(9) {
transform: rotate(-240deg) translateX(5em) rotate(240deg);
z-index: 4;
}
.pl__dot:nth-child(9), .pl__dot:nth-child(9):before, .pl__dot:nth-child(9):after {
animation-delay: -1.3333333333s;
}
.pl__dot:nth-child(10) {
transform: rotate(-270deg) translateX(5em) rotate(270deg);
z-index: 5;
}
.pl__dot:nth-child(10), .pl__dot:nth-child(10):before, .pl__dot:nth-child(10):after {
animation-delay: -1.5s;
}
.pl__dot:nth-child(11) {
transform: rotate(-300deg) translateX(5em) rotate(300deg);
z-index: 6;
}
.pl__dot:nth-child(11), .pl__dot:nth-child(11):before, .pl__dot:nth-child(11):after {
animation-delay: -1.6666666667s;
}
.pl__dot:nth-child(12) {
transform: rotate(-330deg) translateX(5em) rotate(330deg);
z-index: 6;
}
.pl__dot:nth-child(12), .pl__dot:nth-child(12):before, .pl__dot:nth-child(12):after {
animation-delay: -1.8333333333s;
}
另外,随着12个小圆圈逐渐变成小圆柱体,圆柱体的阴影和高度变化被应用到下面的CSS3动画中:
@keyframes shadow {
from {
animation-timing-function: ease-in;
box-shadow: 0.1em 0.1em 0 0.1em black, 0.3em 0 0.3em rgba(0, 0, 0, 0.3);
}
25% {
animation-timing-function: ease-out;
box-shadow: 0.1em 0.1em 0 0.1em black, 0.8em 0 0.8em rgba(0, 0, 0, 0.5);
}
50%, to {
box-shadow: 0.1em 0.1em 0 0.1em black, 0.3em 0 0.3em rgba(0, 0, 0, 0.3);
}
}
@keyframes pushInOut1 {
from {
animation-timing-function: ease-in;
background-color: var(--bg);
transform: translate(0, 0);
}
25% {
animation-timing-function: ease-out;
background-color: var(--primary2);
transform: translate(-71%, -71%);
}
50%, to {
background-color: var(--bg);
transform: translate(0, 0);
}
}
@keyframes pushInOut2 {
from {
animation-timing-function: ease-in;
background-color: var(--bg);
clip-path: polygon(0 75%, 100% 75%, 100% 100%, 0 100%);
}
25% {
animation-timing-function: ease-out;
background-color: var(--primary1);
clip-path: polygon(0 25%, 100% 25%, 100% 100%, 0 100%);
}
50%, to {
background-color: var(--bg);
clip-path: polygon(0 75%, 100% 75%, 100% 100%, 0 100%);
}
}
至此,我们已经完全实现了这个纯CSS3 3D加载动画,文章最后也会把源码献给大家。
源码下载
我已经编译了一个完整的源代码包,供大家下载学习。
© 版权声明
本站下载的源码均来自公开网络收集转发二次开发而来,
若侵犯了您的合法权益,请来信通知我们1413333033@qq.com,
我们会及时删除,给您带来的不便,我们深表歉意。
下载用户仅供学习交流,若使用商业用途,请购买正版授权,否则产生的一切后果将由下载用户自行承担,访问及下载者下载默认同意本站声明的免责申明,请合理使用切勿商用。
THE END
暂无评论内容