javascript - CSS 在整个页面上加载不透明度动画

标签 javascript css

这是我想使用的 CSS 动画。 这是我得到的:

.img {
 width:300px;
 height:100%;
}
.loading {
 content ="Loading";
  background-color: black;
  color: white;
  opacity: 0.5;
  font-family: PT Sans Narrow;

  font-size: 30px;
   top: 45%;
   left: 45%;
   
  position: absolute;
}

.loading:after {
  
  overflow: hidden;
  display: inline-block;
  vertical-align: bottom;
  -webkit-animation: ellipsis steps(5,end) 1000ms infinite;      
  animation: ellipsis steps(5,end) 1000ms infinite;
  content: "\2026\2026"; /* ascii code for the ellipsis character */
  width: 0px;
}

@keyframes ellipsis {
  to {
    width: 1.15em;    
  }
}

@-webkit-keyframes ellipsis {
  to {
    width: 1.5em;    
  }
}
<html>
<div class="loading">Loading</div>

<img src="http://i.imgur.com/iQUErgs.png" class="img"></img>
<img src="http://i.imgur.com/iQUErgs.png" class="img"></img>
<img src="http://i.imgur.com/iQUErgs.png" class="img"></img>
<img src="http://i.imgur.com/iQUErgs.png" class="img"></img>
</html>

目前,在加载图像时背景不会被覆盖,这是一个目标。 我尝试使用内容属性,但它对我来说并没有真正发挥作用。

我想要实现的是当所有图像加载并且屏幕覆盖透明灰色/黑色时,加载带有居中文本的屏幕。

当图像实际加载时,我需要加载屏幕。

最佳答案

我已将以下内容添加到 .loading 中的代码中:

  position: fixed;
  top: 0;
  left: 0;
  height: 100%;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;

position:fixed 允许元素在滚动时 float 在 View 中。 topleft 将固定元素与左上角对齐。为了使文本居中对齐,我使用了 flex。了解有关 Flexbox 的更多信息 herealign-items: center 垂直对齐 Flexbox 元素中的所有元素。 justify-content: center 执行相同的操作,但水平方向除外。

.img {
 width:300px;
 height:100%;
}
.loading {
  content ="Loading";
  background-color: black;
  color: white;
  opacity: 0.5;
  font-family: PT Sans Narrow;

  font-size: 30px;
   
  position: fixed;
  top: 0;
  left: 0;
  height: 100%;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.loading:after {
  
  overflow: hidden;
  display: inline-block;
  vertical-align: bottom;
  -webkit-animation: ellipsis steps(5,end) 1000ms infinite;      
  animation: ellipsis steps(5,end) 1000ms infinite;
  content: "\2026\2026"; /* ascii code for the ellipsis character */
  width: 0px;
}

@keyframes ellipsis {
  to {
    width: 1.15em;    
  }
}

@-webkit-keyframes ellipsis {
  to {
    width: 1.5em;    
  }
}
<html>
<div class="loading">Loading</div>

<img src="http://i.imgur.com/iQUErgs.png" class="img"></img>
<img src="http://i.imgur.com/iQUErgs.png" class="img"></img>
<img src="http://i.imgur.com/iQUErgs.png" class="img"></img>
<img src="http://i.imgur.com/iQUErgs.png" class="img"></img>
</html>

关于javascript - CSS 在整个页面上加载不透明度动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45426849/

相关文章:

Javascript 函数未在 document.ready jquery 代码中定义

javascript - 通过 Javascript 调用 SQLite 时 Firefox 出错

jquery - 长下拉菜单导致页面滚动

html - 如何更改此导航栏颜色?

html - 3D 在这个 HTML 中做什么?

javascript - 如何将值传递给不在 highcharts 中的 x 和 y 轴中的工具提示

javascript - 输入类型为 "Number"的 jQuery

javascript - Angular 2 模板语法

css - 为什么 "word-wrap"css 样式在 <table> (GWT) 中不起作用?

css - 结合 Bootstrap 导航栏和 CSS 网格