3

I want when the component is open to make an animation or to make a fade.

This is the code

This is the HTML

<div *ngIf="showMePartially" class="container">
  <div class="body-container">
</div>
</div>

This is the CSS

.container {
    position: fixed;
    z-index: 1;
    padding-top: 100px;
    transition: opacity 0.5s ease-in;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.4);
    transition: 3s;
}
.body-container {
  width: calc(100% - 73em);
  position: relative;
  left: 70em;
  top: 7.5em;
  background: white;
  height: calc(100% - 18em);
  border-radius: 4px;
  padding-left: 11px; 
  transition: opacity 0.5s ease-in;
  animation-direction: normal;
}
Aleksey Solovey
  • 4,153
  • 3
  • 15
  • 34
TheCoderGuy
  • 771
  • 6
  • 24
  • 51

1 Answers1

4

You can use css animation:

.body-container {
   /* above styles */
   animation: animation-name .3s ease-out forwards;
}

@keyframes animation-name {
  0% {
    opacity: 0;
  }
  100% {
    opacity: 1;
  }
}

You can make your own animation inside of keyframes. This should work, because *ngIf will either remove element from dom, if condition is false, or append it into dom(this is when animation should work).

EDIT For left to right animation you can do like:

@keyframes animation-name {
  0% {
    transform: translateX(100%);
  }
  100% {
    transform: translateX(0%);
  }
}
Azamat Zorkanov
  • 779
  • 1
  • 4
  • 9