HTML代码:

<div id="loading" class="loading">
  <div class="loading-container">
    <div class="loading-circle"></div>
    <div class="loading-text">Loading...</div>
  </div>
</div>

CSS代码:

.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); }
}

JS代码:

function showLoading() {
  document.getElementById("loading").style.display = "block";
}

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

使用方法:

  1. 调用showLoading()函数显示loading
  2. 调用hideLoading()函数隐藏loading

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

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