#loading {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.5);
  z-index: 9999;
  display: none;
}

.loading-icon {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 50px;
  height: 50px;
  border-radius: 50%;
  border: 4px solid #fff;
  border-top-color: #0b5c9b;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}
function showLoading() {
  document.getElementById('loading').style.display = 'block';
}

function hideLoading() {
  document.getElementById('loading').style.display = 'none';
}

调用方法:

showLoading(); // 显示loading
hideLoading(); // 隐藏loading

这个加载效果是一个圆形的旋转加载图标,通过CSS的动画实现旋转效果,同时加上半透明的背景,使整个页面处于禁用状态。JS中提供了两个方法showLoading和hideLoading,分别用于显示和隐藏loading。

纯CSS实现网页加载动画:旋转圆形加载图标

原文地址: https://www.cveoy.top/t/topic/mIWN 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录