利用html+css3代码做一个简单的动态加载效果,下面是具体实现代码,可以直接复制查看效果!
html代码
<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>
css代码
: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;
}
}
以上是编程学习网小编为您介绍的“css3代码做一个动态加载效果”的全面内容,想了解更多关于 前端知识 内容,请继续关注编程基础学习网。
沃梦达教程
本文标题为:css3代码做一个动态加载效果
基础教程推荐
猜你喜欢
- JavaScript整除运算函数ceil和floor的区别分析 2023-11-30
- 使用Ajax、json实现京东购物车结算界面的数据交互实例 2023-01-31
- AJAX请求是否真的不安全?谈一谈Web安全与AJAX的关系 2023-02-15
- 原生JS实现LOADING效果 2023-12-01
- JavaScript+css+HTML实现移动端轮播图(含源码) 2024-03-31
- Angular实现表格自滚动效果 2024-04-03
- Vue开发中最常用的几种UI组件库 2025-01-16
- 第三章之Bootstrap 表格与按钮功能 2024-01-19
- 前端面试学习中几个常见有用的知识点 2024-04-27
- Ajax结合php实现二级联动 2023-01-21