javascript - 如何向网站添加加载屏幕

标签 javascript html css

我为我的网站制作了一个加载屏幕,但有点不知道如何将其附加到它。

我必须在代码中遵循:

body {
  margin: 0;
  padding: 0;
  background: black;
}

.loading {
  width: 200px;
  height: 200px;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.loading h1 {
  color: #4df3ff;
  text-align: center;
}

.loading .circle {
  border-radius: 50%;
  border-left: 4px solid;
  border-right: 4px solid;
  border-top: 4px solid transparent !important;
  border-bottom: 4px solid transparent;
  position: absolute;
  top: 24%;
  left: 50%;
  transform: translate(-50%, -50%);
  animation: rounds 2s infinite;
}

.loading .color1 {
  border-color: #45f3ff;
  width: 220px;
  height: 220px;
}

.loading .color2 {
  border-color: #00474d;
  width: 200px;
  height: 200px;
  animation-delay: 0.2s
}

.loading .color3 {
  border-color: #33f1ff;
  width: 180px;
  height: 180px;
  animation-delay: 0.4s
}

.loading .color4 {
  border-color: #005f66;
  width: 160px;
  height: 160px;
  animation-delay: 0.6s
}

@keyframes rounds {
  0% {
    transform: translate(-50%, -50%) rotate(0deg);
  }
  50% {
    transform: translate(-50%, -50%) rotate(-180deg);
  }
  100% {
    transform: translate(-50%, -50%) rotate(0deg);
  }
}
<div class="loading">
  <h1>Loading..!</h1>
  <div class="circle color1"></div>
  <div class="circle color2"></div>
  <div class="circle color3"></div>
  <div class="circle color4"></div>
</div>

<p>
  Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
  survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing
  software like Aldus PageMaker including versions of Lorem Ipsum. It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less
  normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum'
  will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
</p>

最佳答案

我会把你的加载器放在一个包装器中,让它适合整个窗口,然后在一定时间后隐藏它。

setTimeout(() => {
  document.querySelector('#loading_wrapper').style.display = 'none';
}, 3000);
#loading_wrapper {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background-color: black;
}

.loading {
  width: 200px;
  height: 200px;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.loading h1 {
  color: #4df3ff;
  text-align: center;
}

.loading .circle {
  border-radius: 50%;
  border-left: 4px solid;
  border-right: 4px solid;
  border-top: 4px solid transparent !important;
  border-bottom: 4px solid transparent;
  position: absolute;
  top: 24%;
  left: 50%;
  transform: translate(-50%, -50%);
  animation: rounds 2s infinite;
}

.loading .color1 {
  border-color: #45f3ff;
  width: 220px;
  height: 220px;
}

.loading .color2 {
  border-color: #00474d;
  width: 200px;
  height: 200px;
  animation-delay: 0.2s
}

.loading .color3 {
  border-color: #33f1ff;
  width: 180px;
  height: 180px;
  animation-delay: 0.4s
}

.loading .color4 {
  border-color: #005f66;
  width: 160px;
  height: 160px;
  animation-delay: 0.6s
}

@keyframes rounds {
  0% {
    transform: translate(-50%, -50%) rotate(0deg);
  }
  50% {
    transform: translate(-50%, -50%) rotate(-180deg);
  }
  100% {
    transform: translate(-50%, -50%) rotate(0deg);
  }
}
<div id="loading_wrapper">
  <div class="loading">
    <h1>Loading..!</h1>
    <div class="circle color1"></div>
    <div class="circle color2"></div>
    <div class="circle color3"></div>
    <div class="circle color4"></div>
  </div>
</div>
<p>
  Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
  survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing
  software like Aldus PageMaker including versions of Lorem Ipsum. It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less
  normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum'
  will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
</p>

关于javascript - 如何向网站添加加载屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59639099/

相关文章:

javascript - 单击按钮时飞入内容框?

JavaScript 不会对数字求和

javascript - 如何使用 Node.js 处理 CSS?

javascript - 如何正确缩放 d3 中的图表?

javascript - 使用 jquery 插件 slick carousel 自定义箭头和点

html - 整个页面受悬停效果影响

HTML 和 CSS 裁剪图像高度

css - 在 A4 纸上打印 css A6

javascript - 让 scrollspy 监视标题以外的其他标签

javascript - 隐藏 css 溢出以显示定义的 "window"div 内的图像