0

I want to add an loader in my angular 4 PWA. https://www.w3schools.com/howto/howto_css_loader.asp this loader is visible till all the contents of page get loaded.

<div *ngIf="isLoaded" class="loader"></div>
<div class="home-container" [hidden]="isLoaded"></div>

Initially isLoaded is true after loading all contents it will become false.

loader poistion => top => 0, right = 50%, left = 50%, bottom= 100%

.scss file

.loader {
    border: 16px solid #f3f3f3; /* Light grey */
    border-top: 16px solid #59d4bf; /* green */
    border-radius: 50%;
    margin: auto;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 50px;
    height: 50px;
    -webkit-animation: spin 2s linear infinite;
    animation: spin 2s linear infinite;
}
@keyframes spin {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}

@-webkit-keyframes spin {
    0% {
        -webkit-transform: rotate(0deg);
    }
    100% {
        -webkit-transform: rotate(360deg);
    }
}

here -stackblitz live code sample

core114
  • 5,155
  • 16
  • 92
  • 189
Punj324
  • 215
  • 1
  • 2
  • 9

1 Answers1

1

Your should put your css,

  margin-right: 50%; or  margin-right: auto;
  margin-top: 50%;
  margin-left: 50%; or  margin-right: auto;

your loader

 .loader {
  border: 16px solid #f3f3f3;
  border-radius: 50%;
  border-top: 16px solid #3498db;
  width: 120px; 
  height: 120px;
  -webkit-animation: spin 2s linear infinite; /* Safari */
  animation: spin 2s linear infinite;

  margin-left: 50%;
  margin-right: 50%; 
  margin-top: 50%;
}

is it working , Live working code sample

core114
  • 5,155
  • 16
  • 92
  • 189