Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

187
Vistas
NG ElementRef on CSS transition finished

Problem: CSS animation is throwing off child component (containing html5 canvas) mouse event offsets. Solution: I need to fire an event when a CSS transition has finished.

given:

div{
    -webkit-transition: margin-left 0.3s ease-in-out;
    -moz-transition: margin-left 0.3s ease-in-out;
    -o-transition: margin-left 0.3s ease-in-out;
    transition: margin-left 0.3s ease-in-out;
    &.animate{
         margin-left: 3rem;
    }
}

i can detect when a CSS transition has been completed by:

whichTransitionEvent(){
    var t;
    var el = document.createElement('fakeelement');
    var transitions = {
      'transition':'transitionend',
      'OTransition':'oTransitionEnd',
      'MozTransition':'transitionend',
      'WebkitTransition':'webkitTransitionEnd'
    }

    for(t in transitions){
        if( el.style[t] !== undefined ){
            return transitions[t];
        }
    }
  }

  theFunctionToInvoke(){
  }

  listenForAnimationToFinish(){
    const transitionEnd = this.whichTransitionEvent();
    this.drawerContainer.nativeElement.addEventListener(transitionEnd, this.theFunctionToInvoke, false);
  }

The problem with this solution is that transitionend is not fired on the initial loading of the page. I could also add a timeout on ngAfterViewInit and wait ~300m but that isn't very elegant.

My theory for the root cause is that Javascript Mouse Events is updated when CSS transition events are fired.

Sources:

  • https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/transitionend_event
  • Wait for css transition
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda