Last active
August 29, 2015 14:24
-
-
Save internoma/034f9e661787a6a6b0f4 to your computer and use it in GitHub Desktop.
Detecting CSS Animation and Transition End with JavaScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
By Osvaldas Valutis, www.osvaldas.info | |
Available for use under the MIT License | |
*/ | |
;( function( $, window, document, undefined ) | |
{ | |
var s = document.body || document.documentElement, s = s.style, prefixAnimation = '', prefixTransition = ''; | |
if( s.WebkitAnimation == '' ) prefixAnimation = '-webkit-'; | |
if( s.MozAnimation == '' ) prefixAnimation = '-moz-'; | |
if( s.OAnimation == '' ) prefixAnimation = '-o-'; | |
if( s.WebkitTransition == '' ) prefixTransition = '-webkit-'; | |
if( s.MozTransition == '' ) prefixTransition = '-moz-'; | |
if( s.OTransition == '' ) prefixTransition = '-o-'; | |
$.fn.extend( | |
{ | |
onCSSAnimationEnd: function( callback ) | |
{ | |
var $this = $( this ).eq( 0 ); | |
$this.one( 'webkitAnimationEnd mozAnimationEnd oAnimationEnd oanimationend animationend', callback ); | |
if( ( prefixAnimation == '' && !( 'animation' in s ) ) || $this.css( prefixAnimation + 'animation-duration' ) == '0s' ) callback(); | |
return this; | |
}, | |
onCSSTransitionEnd: function( callback ) | |
{ | |
var $this = $( this ).eq( 0 ); | |
$this.one( 'webkitTransitionEnd mozTransitionEnd oTransitionEnd otransitionend transitionend', callback ); | |
if( ( prefixTransition == '' && !( 'transition' in s ) ) || $this.css( prefixTransition + 'transition-duration' ) == '0s' ) callback(); | |
return this; | |
} | |
}); | |
})( jQuery, window, document ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment