Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

350
Visualizações
Apply CSS transition to element in Angular

I have the following popup element on and Angular 12 application:

<div class="window" [hidden]="!active" (clickOutside)="close()">
  <ng-content select="[window]"></ng-content>
</div> 

Is it possible to apply a CSS transition the DIV shows / hides?

I was considering changing its opacity.

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

I think you're better off using an angular animation. It's more flexible:

This is one I'm using:

import { trigger, state, style, transition, group, animate } from '@angular/animations';

export const FadeInOutAnimation =
  trigger('fadeInOut', [
    state('in', style({
      'opacity': '1',
    })),
    state('out', style({
      'opacity': '0',
    })),
    transition('in => out', [
      group([
        animate('600ms ease-in-out', style({
          'opacity': '0'
        })),
      ])
    ]),
    transition('out => in', [
      group([
        animate('600ms ease-in-out', style({
          'opacity': '1'
        })),
      ])
    ]),
  ]);

And use it:

@Component({
  selector: 'app-popup',
  templateUrl: './popup.component.html',
  styleUrls: ['./popup.component.scss'],
  animations: [
    FadeInOutAnimation
  ]
})
export class PopupComponent implements OnInit {

  constructor() {
  }

  ngOnInit() {
  }

  @Input() dialogVisible: boolean;

}
<div class="popup-background" [@fadeInOut]="dialogVisible"></div>
<div class="popup-content form-control-normal" [@fadeInOut]="dialogVisible">
  <ng-content></ng-content>
</div>

But I think you still have to add the display: block and display: none to the states.

over 4 years ago · Santiago Trujillo Relatório

0

Set the styles in css:

.fade-out {
  visibility: hidden;
  opacity: 0;
  transition: visibility 0s linear 300ms, opacity 1000ms;
}

.fade-in {
  visibility: visible;
  opacity: 1;
  transition: visibility 0s linear 0s, opacity 1000ms;
}

And apply the class in the popup component's HTML:

<div class="container" [class]="active ? 'fade-in' : 'fade-out'">

Check this Stackblitz: https://stackblitz.com/edit/angular-ivy-5whet6?file=src/app/popup/popup.component.html

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda