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

185
Views
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
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!