This article mainly describes how to use CSS to achieve single-element lattice loader effect, has a certain reference value, and now share to everyone, the need for friends can refer to
Source code Download
The full source code of the daily Front end Combat series is available from GitHub:
Https://github.com/comehope/front-end-daily-challenges
Code interpretation
To define the DOM, there are only 1 elements:
<p class= "Loader" ></p>
Center display:
body { margin:0; HEIGHT:100VH; Display:flex; Align-items:center; Justify-content:center; Background:radial-gradient (Darkgreen 30%, forestgreen);}
Define Container Dimensions:
. loader { width:10em; Height:10em; font-size:20px;}
2 groups of dots are drawn with Box-shadow:
. loader::before,.loader::after { content: '; Position:absolute; Width:1em; Height:1em; Background-color:currentcolor; Box-shadow: 0 0, 2em 0, 4em 0, 6em 0, 0 2em, 2em 2em, 4em 2em, 6em 2em, 0 4em, 2em 4em, 4em 4em, 6em 4em, 0 6em, 2em 6em, 4em 6em, 6em 6em; border-radius:50%;}. Loader::before { color:gold;}. loader::after { color:dodgerblue;}
Defining animations:
@keyframes Round { 0% { transform:translatex (0) translatey (0); } 25% { Transform:translatex (3em) translatey (0); } 50% { Transform:translatex (3em) Translatey (3em); } 75% { Transform:translatex (0) Translatey (3em); }}
Finally, apply the animation effect to the dot matrix:
. loader::before,.loader::after { animation:round 2s ease infinite;}. Loader::after { animation-delay: -1s;}
Done!
The above is the whole content of this article, I hope that everyone's learning has helped, more relevant content please pay attention to topic.alibabacloud.com!