Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
CSS:将加载指示器放置在屏幕中央_Css_Position_Center - Fatal编程技术网

CSS:将加载指示器放置在屏幕中央

CSS:将加载指示器放置在屏幕中央,css,position,center,Css,Position,Center,如何将装载指示器放置在屏幕中央。目前我正在使用一个小占位符,它似乎工作得很好。但是,当我向下滚动时,加载指示器保持在预定义的位置。我如何使它跟随滚动,使它始终位于顶部 #busy { position: absolute; left: 50%; top: 35%; display: none; background: transparent url("../images/loading-big.gif"); z-index: 1000; h

如何将装载指示器放置在屏幕中央。目前我正在使用一个小占位符,它似乎工作得很好。但是,当我向下滚动时,加载指示器保持在预定义的位置。我如何使它跟随滚动,使它始终位于顶部

#busy
{
    position: absolute;
    left: 50%;
    top: 35%;
    display: none;
    background: transparent url("../images/loading-big.gif");
    z-index: 1000;
    height: 31px;
    width: 31px;
}

#busy-holder
{
    background: transparent;
    width: 100%;
    height: 100%;        
}

将div busy的绝对位置更改为fixed

使用
位置:fixed
代替
位置:绝对

第一个是相对于您的屏幕窗口。(不受滚动的影响)

第二个是相对于页面的。(受滚动影响)

注意:IE6不支持位置:固定。

.loader{
位置:固定;
左:0px;
顶部:0px;
宽度:100%;
身高:100%;
z指数:9999;
背景:url(“//upload.wikimedia.org/wikipedia/commons/thumb/e/e5/Phi_-fenomeni.gif/50px-Phi_-fenomeni.gif”)
50%50%不重复rgb(249249249);
}

这就是我为Angular 4所做的:

<style type="text/css">  
  .centered {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    transform: -webkit-translate(-50%, -50%);
    transform: -moz-translate(-50%, -50%);
    transform: -ms-translate(-50%, -50%);
    color:darkred;
  }
</style>

</head>

<body>
  <app-root>
        <div class="centered">
          <h1>Loading...</h1>
        </div>
  </app-root>
</body>

.居中{
位置:固定;
最高:50%;
左:50%;
转换:翻译(-50%,-50%);
转换:-webkit翻译(-50%,-50%);
转换:-moz-translate(-50%,-50%);
转换:-ms转换(-50%,-50%);
颜色:深色;
}
加载。。。

在angular 4中为我工作

通过添加
style=“margin:0 auto;”“


您可以使用此加载,也可以在从数据库获取信息时使用

在HTML中添加以下代码:

<div id="divLoading">
<p id="loading">
    <img src="~/images/spinner.gif">
</p>
如果要对JS显示和隐藏:

  document.getElementById('divLoading').style.display = 'none'; //Not Visible
  document.getElementById('divLoading').style.display = 'block';//Visible

这里有一个解决方案,它使用了一个覆盖层,可以禁用材质设计微调器,您可以在应用程序中一次性配置该微调器,并且可以在任何地方调用它

app.component.html (将其放在html的根级别)

app.component.ts messaging.service.ts 你可以试试,这对我来说很管用

<div class="position-relative">
<div class="position-absolute" style="transform: translate(50%, 50%)"> loader or anything Else</div>
</div>

加载器还是别的什么

我不确定你的问题。可能位置:固定。HTML会有帮助。@Kraz:下一个问题是,如何在特定div的中心执行此操作,根据当前的viewport:afaik,目前仅在CSS中是不可行的。需要
position:absolute
fixed
不起作用)和其他由javascript确定的值(顶部,右侧…)。根据您的回答,我终于能够让我的加载程序处于中心位置,无论屏幕大小如何。谢谢!如何将文本也添加到中间
  document.getElementById('divLoading').style.display = 'none'; //Not Visible
  document.getElementById('divLoading').style.display = 'block';//Visible
<div class="overlay" [style.height.px]="height" [style.width.px]="width" *ngIf="message.plzWait$ | async">
        <mat-spinner class="plzWait"  mode="indeterminate"></mat-spinner>
</div>
.plzWait{
  position: relative;
  left: calc(50% - 50px);
  top:50%;

}
.overlay{
  position: absolute;
  top:0px;
  left:0px;
  width: 100%;
  height: 100%;
  background: black;
  opacity: .5;
  z-index: 999999;
}
height = 0;
width = 0;
constructor(
    private message: MessagingService
  }
ngOnInit() {
    this.height = document.body.clientHeight;
    this.width = document.body.clientWidth;
  }
import { Injectable } from '@angular/core';
import { Subject } from 'rxjs';

@Injectable({
    providedIn: 'root',
  })
export class MessagingService {
    // Observable string sources
  private plzWaitObservable = new Subject<boolean>();


  // Public Observables you subscribe to
  public plzWait$ = this.plzWaitObservable.asObservable();

  public plzWait = (wait: boolean) => this.plzWaitObservable.next(wait);
}
constructor(private message: MessagingService) { }
somefunction() {
    this.message.plzWait(true);
    setTimeout(() => {
            this.message.plzWait(false);
    }, 5000);
}
transform: translate(50%, 50%);
<div class="position-relative">
<div class="position-absolute" style="transform: translate(50%, 50%)"> loader or anything Else</div>
</div>