前端页面加载Loading动画
    		       		warning:
    		            这篇文章距离上次修改已过442天,其中的内容可能已经有所变动。
    		        
        		                
                在前端页面中添加Loading动画通常是为了在页面资源加载过程中给用户一个视觉上的反馈,减少用户的不确定感。以下是一个简单的Loading动画实现方法,使用了HTML和CSS。
HTML部分:
<div class="loading-overlay">
  <div class="loading-content">
    <div class="loading-icon"></div>
    <div class="loading-text">加载中...</div>
  </div>
</div>CSS部分:
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(255, 255, 255, 0.7);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000; /* Ensure it's above other content */
}
 
.loading-content {
  display: flex;
  flex-direction: column;
  align-items: center;
}
 
.loading-icon {
  width: 50px;
  height: 50px;
  border: 6px solid #f3f3f3;
  border-top: 6px solid #3498db;
  border-radius: 50%;
  animation: spin 2s linear infinite;
}
 
.loading-text {
  margin-top: 10px;
  font-size: 16px;
  color: #333;
}
 
@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}在页面的<body>标签中添加上述HTML代码,并在<head>标签中或者一个外部的CSS文件中添加CSS代码。这样,当页面加载时,Loading动画会显示在页面中央,加载完成后,需要将.loading-overlay元素从DOM中移除。
评论已关闭