本篇文章给大家带来的内容是关于如何使用纯css实现菱形loader效果(附源码),有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。
效果预览

源代码下载
https://github.com/comehope/front-end-daily-challenges
代码解读
定义 dom,一个容器中包含 9 个子元素:
居中显示:
立即学习“前端免费学习笔记(深入)”;
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效果(附源码)的详细内容,更多请关注创想鸟其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/1611922.html
微信扫一扫
支付宝扫一扫