How to use pure CSS to achieve diamond loader effect
This article mainly shows you "how to use pure CSS to achieve diamond loader effect", the content is easy to understand, clear, hope to help you solve your doubts, the following let Xiaobian lead you to study and learn "how to use pure CSS to achieve diamond loader effect" this article.
Code interpretation
Define dom, which contains nine child elements in a container:
Centered display:
Body {
Margin:0
Height:100vh
Display:flex
Align-items:center
Justify-content:center
Background-color:black
}
Defines the size of the container and child elements, which is a large square containing 9 small squares:
.loader {
Width:10em
Height:10em
Display:grid
Grid-template-columns:repeat (3Jing 1fr)
Grid-gap:0.5em
}
Adjust the pattern to include 9 small diamonds in the big diamond:
.loader {
Transform:rotate (45deg)
}
To color a small diamond in vertical units:
.loaderspan {
Background-color:var (--c)
}
.loaderspan:nth-child (7) {
-- c:tomato
}
.loaderspan:nth-child (4)
.loaderspan:nth-child (8) {
-- c:gold
}
.loaderspan:nth-child (1)
.loaderspan:nth-child (5)
.loaderspan:nth-child (9) {
-- c:limegreen
}
.loaderspan:nth-child (2)
.loaderspan:nth-child (6) {
-- c:dodgerblue
}
.loaderspan:nth-child (3) {
-- c:mediumpurple
}
Define animation effects:
.loaderspan {
Animation:blinking2slinearinfinite
Animation-delay:var (--d)
Transform:scale (0)
}
@ keyframesblinking {
0% 100% {
Transform:scale (0)
}
40% 80% {
Transform:scale (1)
}
}
Finally, set the delay for the small diamond to enhance the sense of motion:
.loaderspan:nth-child (7) {
-- dDRO _ 0s
}
.loaderspan:nth-child (4)
.loaderspan:nth-child (8) {
-- dvl 0.2s
}
.loaderspan:nth-child (1)
.loaderspan:nth-child (5)
.loaderspan:nth-child (9) {
-- dDUR 0.4s
}
.loaderspan:nth-child (2)
.loaderspan:nth-child (6) {
-- dvl 0.6s
}
.loaderspan:nth-child (3) {
-- dvl 0.8s
}
The above is all the content of this article "how to achieve diamond loader effect with pure CSS". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!