1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

angular 2 ngIf and CSS transition/animation

Discussão em 'Angular' iniciado por Han Che, Agosto 12, 2025.

  1. Han Che

    Han Che Guest

    I want a div to slide in from the right in angular 2 using css.

    <div class="note" [ngClass]="{'transition':show}" *ngIf="show">
    <p> Notes</p>
    </div>
    <button class="btn btn-default" (click)="toggle(show)">Toggle</button>


    I works fine if i only use [ngClass] to toggle class and utilise opacity. But li don't want that element to be rendered from the beginning so I "hide" it with ngIf first, but then the transition wont't work.

    .transition{
    -webkit-transition: opacity 1000ms ease-in-out,margin-left 500ms ease-in-out;
    -moz-transition: opacity 1000ms ease-in-out,margin-left 500ms ease-in-out;
    -ms-transition: opacity 1000ms ease-in-out,margin-left 500ms ease-in-out ;
    -o-transition: opacity 1000ms ease-in-out,margin-left 500ms ease-in-out;
    transition: opacity 1000ms ease-in-out,margin-left 500ms ease-in-out;
    margin-left: 1500px;
    width: 200px;
    opacity: 0;
    }

    .transition{
    opacity: 100;
    margin-left: 0;
    }

    Continue reading...

Compartilhe esta Página