【问题标题】:custom spinner (logo) in AngularAngular 中的自定义微调器(徽标)
【发布时间】:2020-03-03 09:06:42
【问题描述】:

我想在 Angular 项目中创建一个自定义微调器/加载器。我已经到处搜索了这个,但我只能找到创建不同微调器的帮助,但甚至找不到使用图像的微调器。任何人都可以帮助或指出我正确的方向吗?如果我只使用 CSS 和 HTML,它不会在我需要时加载。

【问题讨论】:

  • 请发表您的尝试以及您的预期结果。
  • 我的标志是 png 格式。我希望它成为我的微调器,并可能在下面添加加载单词。我还没试过。
  • 您想在整个页面上显示它吗?你想什么时候展示?
  • 我会尝试用普通的 HTML/CSS 来做,然后查看一些关于在 Angular 中创建组件的基本教程。网上有很多资源。

标签: angular spinner loader


【解决方案1】:

这是我的代码示例,用于在 Angular 应用程序的早期项目中创建图像微调器(在纯 css/html 中完成):

html:

<div *ngIf="loaderPersonInfo" class="spinner">
  <img class="spinner-img" src="../../../assets/img/logo.svg">
</div>

css:

.spinner-img {
  height: 20vh;
  width: 20vh;
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  margin: auto;
  animation: loading-spinner-img 3s linear infinite;
}


@keyframes loading-spinner-img {
  0%, 100% {
    animation-timing-function: cubic-bezier(0.5, 0, 1, 0.5);
  }
  0% {
    transform: rotateY(0deg);
  }
  50% {
    transform: rotateY(1800deg);
    animation-timing-function: cubic-bezier(0, 0.5, 0.5, 1);
  }
  100% {
    transform: rotateY(3600deg);
  }
}

【讨论】:

  • 感谢所有答案。我被告知现在要做其他事情,但我会回到这个并尝试你的建议。谢谢!
【解决方案2】:

使用这个

要使用微调器的 HTML 部分

 <div class="overlay" *ngIf="showSpinner">
    <div class="spinner-wrapper">
      <app-spinner message="Data Loading"></app-spinner>
    </div>
  </div>

  <div class="loaded-content" [class.blurred]="showSpinner">
  </div>

Css 部分

    .overlay {
    position: absolute;
    z-index: 1002;
    background-color: rgba(255, 255, 255, 0.5);
    width: 100%;
    height: 100%;
  }

  .spinner-wrapper {
    display: flex;
    justify-content: center;
    justify-items: center;
  }

如下创建一个微调器组件

组件html

<div class="container">
  <div class="row">
    <div id="loader">
      <div class="dot"></div>
      <div class="dot"></div>
      <div class="dot"></div>
      <div class="dot"></div>
      <div class="dot"></div>
      <div class="dot"></div>
      <div class="dot"></div>
      <div class="dot"></div>
      <div class="loading"></div>
    </div>

    <p class="spinner-message" *ngIf="message && message !== ''">
      {{message}}
    </p>
  </div>
</div> 

组件 CSS

#loader {
    bottom: 0;
    height: 175px;
    left: 0;
    margin: auto;
    position: absolute;
    right: 0;
    top: 0;
    width: 175px;
  }

  #loader {
    bottom: 0;
    height: 175px;
    left: 0;
    margin: auto;
    position: absolute;
    right: 0;
    top: 0;
    width: 175px;
  }

  #loader .dot {
    bottom: 0;
    height: 100%;
    left: 0;
    margin: auto;
    position: absolute;
    right: 0;
    top: 0;
    width: 87.5px;
  }

  #loader .dot::before {
    border-radius: 100%;
    content: "";
    height: 87.5px;
    left: 0;
    position: absolute;
    right: 0;
    top: 0;
    transform: scale(0);
    width: 87.5px;
  }

  #loader .dot:nth-child(7n+1) {
    transform: rotate(45deg);
  }

  #loader .dot:nth-child(7n+1)::before {
    animation: 0.8s linear 0.1s normal none infinite running load;
    background: #00ff80 none repeat scroll 0 0;
  }

  #loader .dot:nth-child(7n+2) {
    transform: rotate(90deg);
  }

  #loader .dot:nth-child(7n+2)::before {
    animation: 0.8s linear 0.2s normal none infinite running load;
    background: #00ffea none repeat scroll 0 0;
  }

  #loader .dot:nth-child(7n+3) {
    transform: rotate(135deg);
  }

  #loader .dot:nth-child(7n+3)::before {
    animation: 0.8s linear 0.3s normal none infinite running load;
    background: #00aaff none repeat scroll 0 0;
  }

  #loader .dot:nth-child(7n+4) {
    transform: rotate(180deg);
  }

  #loader .dot:nth-child(7n+4)::before {
    animation: 0.8s linear 0.4s normal none infinite running load;
    background: #0040ff none repeat scroll 0 0;
  }

  #loader .dot:nth-child(7n+5) {
    transform: rotate(225deg);
  }

  #loader .dot:nth-child(7n+5)::before {
    animation: 0.8s linear 0.5s normal none infinite running load;
    background: #2a00ff none repeat scroll 0 0;
  }

  #loader .dot:nth-child(7n+6) {
    transform: rotate(270deg);
  }

  #loader .dot:nth-child(7n+6)::before {
    animation: 0.8s linear 0.6s normal none infinite running load;
    background: #9500ff none repeat scroll 0 0;
  }

  #loader .dot:nth-child(7n+7) {
    transform: rotate(315deg);
  }

  #loader .dot:nth-child(7n+7)::before {
    animation: 0.8s linear 0.7s normal none infinite running load;
    background: magenta none repeat scroll 0 0;
  }

  #loader .dot:nth-child(7n+8) {
    transform: rotate(360deg);
  }

  #loader .dot:nth-child(7n+8)::before {
    animation: 0.8s linear 0.8s normal none infinite running load;
    background: #ff0095 none repeat scroll 0 0;
  }

  #loader .loading {
    background-position: 50% 50%;
    background-repeat: no-repeat;
    bottom: -40px;
    height: 20px;
    left: 0;
    position: absolute;
    right: 0;
    width: 180px;
  }

  @keyframes load {
    100% {
      opacity: 0;
      transform: scale(1);
    }
  }

  @keyframes load {
    100% {
      opacity: 0;
      transform: scale(1);
    }
  }

  .spinner-message {
    text-align: center;
  }

组件 ts 部分

export class SpinnerComponent implements OnInit {
  @Input() message = '';
  constructor() { }

  ngOnInit() {
  }

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-13
    相关资源
    最近更新 更多