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

233
Visualizações
Animation for newly rendered elements, but not on page load

I'm subscribed to a Firebase real-time database so that when I submit something to it, it immediately renders in the view without any need for jQuery or ajax.

I'd like to animate the rendering of such elements, so that when a new element is added to the DOM its div's background-color is green and slowly fades away. What I don't want is for all divs of this class to perform this animation on load.

I know how to do the former:

@keyframes green-fade {
    0% {background: rgb(173, 235, 173);}
    100% {background: none;}
}

.post-div {
   animation: green-fade 5s ease-in 1;
}

But of course this animation happens for this class any time it's rendered, including on load.

I'm interested in the "Angular 2 way" to do this.

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

0

Since Angular 4.25 there's an easier way to do this: If you want to suppress an :enter animation on view initialization, just wrap it with the following animation:

template: `
  <div [@preventInitialChildAnimations]>
    <div [@someAnimation]>...</div>
  </div>
`,
animations: [
  trigger('preventInitialChildAnimations', [
    transition(':enter', [
      query(':enter', [], {optional: true})
    ])
  ]),
  ...
]
over 4 years ago · Santiago Trujillo Relatório

0

Easiest solution:

 @Component({
    selector: 'myComponent',
    template: '<div [@.disabled]="disableAnimations" [@someAnimation]="someValue">',
    animations: [trigger('someAnimation', [transition('* => *', [style({ transform: 'scale(1.1)' }), animate(250)])])]
})
export class MyComponent implements AfterViewInit {

    disableAnimations: boolean = true;

    constructor() {}

    ngAfterViewInit(): void {
        this.disableAnimations = false;
    }
}

Reference: https://angular.io/api/animations/trigger (scroll to "disable animations")

over 4 years ago · Santiago Trujillo Relatório

0

Add a trigger that checks the state of a item when it comes through the network. Here I'm triggering the animation when itemState is new.

    trigger('itemState', [
      transition('* => new', animate(5000, keyframes([
        style({ backgroundColor: 'red', offset: 0 }),
        style({ backgroundColor: '*', offset: 1.0 })
      ]))),

Give your trigger a reference to the state of your item, and set it to null when the animation finishes.

<div [@itemState]="someItem.itemState" (@itemState.done)="someItem.itemState=''">

Be sure to add an itemState property to your posts so that you can flag them as new!

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