Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

352
Views
Aplicar la transición CSS al elemento en Angular

Tengo el siguiente elemento emergente en una aplicación Angular 12:

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

¿Es posible aplicar una transición CSS que el DIV muestra/oculta?

Estaba considerando cambiar su opacidad.

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Creo que es mejor usar una animación angular. Es más flexible:

Este es uno que estoy usando:

 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' })), ]) ]), ]);

Y úsalo:

 @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>

Pero creo que aún debe agregar display: block y display: none a los estados.

over 4 years ago · Santiago Trujillo Report

0

Establecer los estilos en 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; }

Y aplique la clase en el HTML del componente emergente:

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

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

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!