https://github.com/comehope/front-end-daily-challenges
定义 dom,一个容器中包含 9 个子元素:
<div class="loader"> <span></span> <span></span> <span></span> <span></span> <span></span> <span></span> <span></span> <span></span> <span></span> </div>
居中显示:
body { margin: 0; height: 100vh; display: flex; align-items: center; justify-content: center; background-color: black; }
定义容器和子元素尺寸,是一个大正方形里包含 9 个小正方形:
.loader { width: 10em; height: 10em; display: grid; grid-template-columns: repeat(3, 1fr); grid-gap: 0.5em; }把图案调整为大菱形中包含 9 个小菱形:
.loader { transform: rotate(45deg); }以竖向的小菱形为单位,为小菱形块上色:
.loader span { background-color: var(--c); } .loader span:nth-child(7) { --c: tomato; } .loader span:nth-child(4), .loader span:nth-child(8) { --c: gold; } .loader span:nth-child(1), .loader span:nth-child(5), .loader span:nth-child(9) { --c: limegreen; } .loader span:nth-child(2), .loader span:nth-child(6) { --c: dodgerblue; } .loader span:nth-child(3) { --c: mediumpurple; }定义动画效果:
.loader span { animation: blinking 2s linear infinite; animation-delay: var(--d); transform: scale(0); } @keyframes blinking { 0%, 100% { transform: scale(0); } 40%, 80% { transform: scale(1); } }最后,为小菱形设置时延,增强动感:
.loader span:nth-child(7) { --d: 0s; } .loader span:nth-child(4), .loader span:nth-child(8) { --d: 0.2s; } .loader span:nth-child(1), .loader span:nth-child(5), .loader span:nth-child(9) { --d: 0.4s; } .loader span:nth-child(2), .loader span:nth-child(6) { --d: 0.6s; } .loader span:nth-child(3) { --d: 0.8s; }大功告成!
以上就是如何使用纯CSS实现菱形loader效果(附源码)的详细内容,更多请关注php中文网其它相关文章!
网站建设是一个广义的术语,涵盖了许多不同的技能和学科中所使用的生产和维护的网站。……