Created
March 10, 2015 07:22
-
-
Save mattmccray/a8bdec36cf9ac8943fb5 to your computer and use it in GitHub Desktop.
React AnimationMixin - for Animate.css
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
// Extracted from a live application. Known to work with latest Chrome/Firefox | |
// and Animate.css. (IE untested) | |
export let AnimationMixin= { | |
playAnimation( animation='pulse', speed=1000) { | |
if(! this.isMounted()) { | |
log.warn( "Trying to call .playAnimation() on an unmounted component!") | |
return | |
} | |
let node= this.getDOMNode() | |
if(! node.classList.contains( 'animated')) { | |
node.classList.add( 'animated') | |
} | |
if( this._animating) { | |
node.classList.remove( this._animating) | |
clearTimeout( this._animationTimer) | |
this._animating= false | |
forceRepaint( node) | |
} | |
node.style.animationDuration= speed +'ms' | |
node.classList.add( animation) | |
this._animating= animation | |
this._animationTimer= setTimeout(() => { | |
node.classList.remove( this._animating) | |
this._animating= false | |
}, speed + 1) | |
} | |
} | |
function forceRepaint( node) { | |
node.parentNode.style.cssText += ';-webkit-transform:rotateZ(0deg)' | |
node.parentNode.offsetHeight // jshint ignore:line | |
node.parentNode.style.cssText += ';-webkit-transform:none' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment