Results preview
Press the right "click the Preview" button to preview the current page, click on the link to full-screen preview.
https://codepen.io/comehope/pen/KBxYZg/
Interactive video
This video is interactive, you can pause the code video, editing video.
Please use chrome, safari, edge open view.
https://scrimba.com/p/pEgDAM/cagbkSL
Source code download
Daily front-end combat series full source code can be downloaded from github:
https://github.com/comehope/front-end-daily-challenges
Code Reading
Defined dom, elements contained in the container 3, representing three dots:
<div class="loader">
<span></span>
<span></span>
<span></span>
</div>
Centered:
body {
margin: 0;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
background: linear-gradient(to right, silver, teal);
}
Ferris wheel diameter is defined, the other is the length of this basic measure are:
.loader {
--diameter: 10em;
}
Defined size of the container, the width is 2 times:
.loader {
--width: calc(var(--diameter) * 2);
width: var(--width);
height: var(--diameter);
}
Sharing attributes define pseudo-element:
.loader {
position: relative;
}
.loader::before,
.loader::after {
content: '';
position: absolute;
bottom: 0;
}
Orbitally bottom, while a line indicating the definition of a variable thickness:
.loader {
--stroke-width: calc(var(--diameter) / 40);
color: white;
}
.loader::before {
width: inherit;
height: var(--stroke-width);
background-color: currentColor;
}
Draw central circular orbit:
.loader::after {
box-sizing: border-box;
width: var(--diameter);
height: var(--diameter);
border: var(--stroke-width) solid;
border-radius: 50%;
left: 25%;
}
Draw a dot, while the dot denotes defines a variable diameter:
.loader {
--dot-diameter: calc(var(--diameter) / 10);
}
.loader span {
position: absolute;
width: var(--dot-diameter);
height: var(--dot-diameter);
background-color: currentColor;
border-radius: 50%;
bottom: var(--stroke-width);
left: calc((var(--width) - var(--dot-diameter)) / 2);
}
For the dots increasing along a circular orbit of rotation animation:
.loader span {
animation:
rotating 2s linear infinite;
--vertical-center: calc((var(--diameter) / 2 - var(--stroke-width) - var(--dot-diameter)) * -1);
transform-origin: 50% var(--vertical-center);
}
@keyframes rotating {
0%, 10% {
transform: rotate(0deg);
}
60%, 100% {
transform: rotate(-1turn);
}
}
Dot increase for the animation moves:
.loader span {
animation:
run 2s linear infinite,
rotating 2s linear infinite;
}
@keyframes run {
0% {
left: calc(var(--dot-diameter) * -1);
}
10%, 60% {
left: calc((var(--width) - var(--dot-diameter)) / 2);
}
70%, 100% {
left: calc(var(--width));
}
}
Also provided is a two dot delay animation that looks like three dots next three compartments:
.loader span:nth-child(1) {
animation-delay: 0.075s;
}
.loader span:nth-child(2) {
animation-delay: 0.15s;
}
Finally, hidden content outside the container:
.loader {
overflow: hidden;
}
We're done!