纯CSS实现加载动画弹窗效果 - 代码示例与使用方法
Loading...
.loading {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.7);
z-index: 9999;
display: none;
}
.loading-container {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
text-align: center;
}
.loading-circle {
border: 4px solid #f3f3f3;
border-top: 4px solid #3498db;
border-radius: 50%;
width: 30px;
height: 30px;
animation: spin 2s linear infinite;
}
.loading-text {
font-size: 16px;
color: #fff;
margin-top: 10px;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
function showLoading() {
document.getElementById('loading').style.display = 'block';
}
function hideLoading() {
document.getElementById('loading').style.display = 'none';
}
使用方法:
- 调用
showLoading()函数显示loading - 调用
hideLoading()函数隐藏loading
本示例使用纯CSS代码实现加载动画弹窗,简单易懂且易于使用。您可以在项目中根据需要修改样式和动画效果。
原文地址: https://www.cveoy.top/t/topic/mIWv 著作权归作者所有。请勿转载和采集!