Skip to content

Instantly share code, notes, and snippets.

@ingowennemaring
Created August 6, 2015 15:54
Show Gist options
  • Save ingowennemaring/540587d9df3937525e96 to your computer and use it in GitHub Desktop.
Save ingowennemaring/540587d9df3937525e96 to your computer and use it in GitHub Desktop.
Trigger css animations via JavaScript
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