返回
为网站增添一份灵动——CSS打造的精简加载动画
前端
2023-11-07 03:52:02
样式一:流动线条
用纯CSS制作一个类似于加载中常见的环状转圈转圈加载动画。
div.loading1 {
width: 60px;
height: 60px;
margin: 100px auto;
border-radius: 50%;
position: relative;
text-align: center;
}
div.loading1 span {
width: 20px;
height: 20px;
border-radius: 50%;
position: absolute;
opacity: 0;
-webkit-animation: animate 2s linear infinite;
animation: animate 2s linear infinite;
}
div.loading1 span:nth-child(1) {
top: 0;
left: 0;
-webkit-animation-delay: 0s;
animation-delay: 0s;
}
div.loading1 span:nth-child(2) {
top: 0;
right: 0;
-webkit-animation-delay: 0.2s;
animation-delay: 0.2s;
}
div.loading1 span:nth-child(3) {
bottom: 0;
right: 0;
-webkit-animation-delay: 0.4s;
animation-delay: 0.4s;
}
div.loading1 span:nth-child(4) {
bottom: 0;
left: 0;
-webkit-animation-delay: 0.6s;
animation-delay: 0.6s;
}
@-webkit-keyframes animate {
0% {
opacity: 1;
}
25% {
opacity: 1;
}
50% {
opacity: 0;
}
75% {
opacity: 0;
}
100% {
opacity: 1;
}
}
@keyframes animate {
0% {
opacity: 1;
}
25% {
opacity: 1;
}
50% {
opacity: 0;
}
75% {
opacity: 0;
}
100% {
opacity: 1;
}
}
样式二:弹性加载
使用类似于橡胶皮筋的弹性效果制作一个动态十足的加载动画。
div.loading2 {
width: 100px;
height: 100px;
margin: 100px auto;
border: 10px solid #ccc;
border-radius: 50%;
animation: animate 2s linear infinite;
}
@keyframes animate {
0% {
transform: scale(1);
}
50% {
transform: scale(1.2);
}
100% {
transform: scale(1);
}
}
应用场景
以上提供的两个加载动画可以轻松应用于各种网站场景。无论你是想在页面加载时添加一个有趣的视觉效果,还是想在按钮点击时提供一个反馈,这些动画都能满足你的需求。你可以在此基础上进一步发挥你的创意,制作出更多个性化的动画效果。