Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use transitionend in jQuery?

I need to detect if a CSS transition is completed before allowing a function to repeat again, to prevent messing up the margins.

So how cam I have something like

if (transitionend == true) {   // do stuff } else {   // do nothing } 
like image 512
JacobTheDev Avatar asked Aug 20 '11 20:08

JacobTheDev


People also ask

What is Transitionend?

The transitionend event occurs when a CSS transition has completed. Note: If the transition is removed before completion, e.g. if the CSS transition-property property is removed, the transitionend event will not fire. For more information about CSS Transitions, see our tutorial on CSS3 Transitions.


1 Answers

The code below will trigger on the transitionend event for whatever element(s) you have in the $element variable. There are four different event names as I believe these cover all of the cross-browser inconsistencies. Replace the '// your event handler' comment with whatever code you wish to run when the event is triggered.

$element.on('transitionend webkitTransitionEnd oTransitionEnd', function () {     // your event handler }); 
like image 74
xram Avatar answered Sep 17 '22 14:09

xram