码字不易,有帮助的同学希望能关注一下我的微信公众号:Code程序人生,感谢!代码自用自取。
在任何项目都中会出现需要加载的数据的场景,大多数都会给一个loading的交互提示,这期我们就做一个超级好看炫酷的加载动画。大家可以封装一下,进行复用。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
section {
position:relative;
width: 100%;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
background: #001300;
animation: changeColor 5s linear infinite;
}
@keyframes changeColor {
0% {
filter: hue-rotate(0deg);
}
100% {
filter: hue-rotate(360deg);
}
}
section h2 {
color:#00ff0a;
font-family: consolas;
font-weight: 300;
letter-spacing: 10px;
}
section .loader {
position: relative;
display: flex;
}
section .loader .dot {
position:relative;
display: block;
width: 20px;
height: 20px;
background: #00ff0a;
box-shadow: 0 0 10px #00ff0a,
0 0 20px #00ff0a,
0 0 40px #00ff0a,
0 0 60px #00ff0a,
0 0 80px #00ff0a,
0 0 100px #00ff0a;
margin: 20px 10px;
transform: scale(0,1);
border-radius: 50%;
animation: animateDot 2s linear infinite;
animation-delay: calc(0.1s * var(--i));
}
section .loader:last-child .dot {
animation-delay: calc(-0.1s * var(--i));
}
@keyframes animateDot {
0% {
transform: scale(0.1);
}
10% {
transform: scale(1);
}
50%,100% {
transform: scale(0.1);
}
}
</style>
</head>
<body>
<section>
<div class="loader">
<div class="dot" style="--i:0;"></div>
<div class="dot" style="--i:1"></div>
<div class="dot" style="--i:2"></div>
<div class="dot" style="--i:3"></div>
<div class="dot" style="--i:4"></div>
<div class="dot" style="--i:5"></div>
<div class="dot" style="--i:6"></div>
<div class="dot" style="--i:7"></div>
<div class="dot" style="--i:8"></div>
<div class="dot" style="--i:9"></div>
</div>
<h2>Loading...</h2>
<div class="loader">
<div class="dot" style="--i:0;"></div>
<div class="dot" style="--i:1"></div>
<div class="dot" style="--i:2"></div>
<div class="dot" style="--i:3"></div>
<div class="dot" style="--i:4"></div>
<div class="dot" style="--i:5"></div>
<div class="dot" style="--i:6"></div>
<div class="dot" style="--i:7"></div>
<div class="dot" style="--i:8"></div>
<div class="dot" style="--i:9"></div>
</div>
</section>
</body>
</html>
效果图: