2024年03月28日 建站教程
利用html+css3代码做一个简单的动态加载效果,下面是具体实现代码,可以直接复制查看效果!
<input type="checkbox"/> <div class="bg"></div> <div class="content"> <div class="dots"> <div class="dot"><span></span></div> <div class="dot"><span></span></div> <div class="dot"><span></span></div> <div class="dot"><span></span></div> <div class="dot"><span></span></div> <div class="dot"><span></span></div> <div class="dot"><span></span></div> <div class="dot"><span></span></div> <div class="dot"><span></span></div> <div class="dot"><span></span></div> <div class="dot"><span></span></div> <div class="dot"><span></span></div> <div class="ring"></div> </div> </div>
:root { --w: #fafafa; --b: #141414; --s: 1s; --d: calc(var(--s) / 6); } * { box-sizing: border-box; } body { margin: 0; padding: 0; width: 100vw; height: 100vh; overflow: hidden; } input { width: 100vw; height: 100vh; position: absolute; z-index: 4; opacity: 0; cursor: pointer; } input:checked ~ div { filter: invert(1); } input:checked + .bg:before { content: "CLICK TO DARK"; } .bg:before { content: "CLICK TO LIGHT"; position: absolute; color: var(--w); width: 100%; text-align: center; bottom: 10vh; font-family: Arial, Helvetica, serif; font-size: 12px; text-shadow: 0 0 1px var(--w); opacity: 0.25; } body, .content, .dots { display: flex; align-items: center; justify-content: center; } .bg { width: 100vw; height: 100vh; position: absolute; background: var(--b); z-index: -2; } .content { width: 50vmin; height: 50vmin; background: #f000; animation: spin 8s linear 0s infinite; } .dots { background: #0ff0; width: 100%; height: 100%; position: relative; } .ring { border: 1.5vmin solid var(--w); width: 64%; height: 64%; border-radius: 100%; z-index: 0; box-shadow: 0 0 0 1vmin var(--b), 0 0 0 1vmin var(--b) inset; animation: spin 8s linear 0s infinite reverse; } .dot { width: 50%; position: absolute; height: 7vmin; background: #f000; left: 0; transform-origin: 100% 50%; z-index: -1; animation: over-ring calc(var(--s) * 2) linear 0s infinite; } .dot span { width: 5.5vmin; height: 5.5vmin; left: 0; border: 1vmin solid var(--b); position: absolute; background: var(--w); border-radius: 100%; animation: ball var(--s) ease-in-out 0s infinite alternate; } .dot:nth-child(1) { transform: rotate(-30deg); animation-delay: calc(var(--d) * 0); } .dot:nth-child(1) span { animation-delay: calc(var(--d) * 0); } .dot:nth-child(2) { transform: rotate(-60deg); animation-delay: calc(var(--d) * -1); } .dot:nth-child(2) span { animation-delay: calc(var(--d) * -1); } .dot:nth-child(3) { transform: rotate(-90deg); animation-delay: calc(var(--d) * -2); } .dot:nth-child(3) span { animation-delay: calc(var(--d) * -2); } .dot:nth-child(4) { transform: rotate(-120deg); animation-delay: calc(var(--d) * -3); } .dot:nth-child(4) span { animation-delay: calc(var(--d) * -3); } .dot:nth-child(5) { transform: rotate(-150deg); animation-delay: calc(var(--d) * -4); } .dot:nth-child(5) span { animation-delay: calc(var(--d) * -4); } .dot:nth-child(6) { transform: rotate(-180deg); animation-delay: calc(var(--d) * -5); } .dot:nth-child(6) span { animation-delay: calc(var(--d) * -5); } .dot:nth-child(7) { transform: rotate(-210deg); animation-delay: calc(var(--d) * -6); } .dot:nth-child(7) span { animation-delay: calc(var(--d) * -6); } .dot:nth-child(8) { transform: rotate(-240deg); animation-delay: calc(var(--d) * -7); } .dot:nth-child(8) span { animation-delay: calc(var(--d) * -7); } .dot:nth-child(9) { transform: rotate(-270deg); animation-delay: calc(var(--d) * -8); } .dot:nth-child(9) span { animation-delay: calc(var(--d) * -8); } .dot:nth-child(10) { transform: rotate(-300deg); animation-delay: calc(var(--d) * -9); } .dot:nth-child(10) span { animation-delay: calc(var(--d) * -9); } .dot:nth-child(11) { transform: rotate(-330deg); animation-delay: calc(var(--d) * -10); } .dot:nth-child(11) span { animation-delay: calc(var(--d) * -10); } .dot:nth-child(12) { transform: rotate(-360deg); animation-delay: calc(var(--d) * -11); } .dot:nth-child(12) span { animation-delay: calc(var(--d) * -11); } @keyframes spin { 100% { transform: rotate(-360deg); } } @keyframes ball { 100% { left: 12vmin; width: 4vmin; height: 4vmin; } } @keyframes over-ring { 0%, 50% { z-index: -1; } 51%, 100% { z-index: 1; } }
本文链接:http://so.lmcjl.com/news/537/