Created
August 6, 2015 15:54
-
-
Save ingowennemaring/540587d9df3937525e96 to your computer and use it in GitHub Desktop.
Trigger css animations via JavaScript
This file contains 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
function cssAni ( mode, elem ) { | |
var show = function () { | |
// timeout nötig für Fx => sonst kein transition-Event | |
setTimeout( function () { | |
elem.addClass( 'transition visible' ); | |
}, 100 ); | |
}; | |
var hide = function () { | |
if ( SRLIB.supports( 'transition' ) ) { | |
var isTransition = parseFloat( elem.css( 'transition-duration' ) ); | |
// timeout nötig für Fx => sonst kein transition-Event | |
setTimeout( function () { | |
elem.removeClass( 'visible' ); | |
if ( !isTransition ) { | |
elem.removeClass( 'transition' ); | |
} | |
}, 100 ); | |
if ( isTransition ) { | |
elem.on( | |
'webkitTransitionEnd msTransitionEnd oTransitionEnd transitionend', | |
function () { | |
elem | |
.removeAttr( 'style' ) | |
.removeClass( 'transition' ) | |
.off( | |
'webkitTransitionEnd msTransitionEnd oTransitionEnd transitionend' | |
); | |
} | |
); | |
} | |
} else { | |
elem.removeClass( 'transition visible' ).removeAttr( 'style' ); | |
} | |
}; | |
if ( mode === 'show' ) { | |
show(); | |
} else { | |
hide(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment