Last active
December 19, 2015 21:49
-
-
Save jwerle/6023429 to your computer and use it in GitHub Desktop.
stop animation frame
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 stopAnimations () { | |
// Get the Body Element | |
var body = document.body | |
body.addEventListener('webkitAnimationStart', stopAnimation, false); | |
body.addEventListener('webkitAnimationIteration', stopAnimation, false); | |
body.addEventListener('animationstart', stopAnimation, false); | |
body.addEventListener('animationiteration', stopAnimation, false); | |
function stopAnimation (e) { | |
var target = e.target; | |
var type = e.type.toLowerCase(); | |
if (!!~type.indexOf('animationstart') || !!~type.indexOf('animationiteration')) { | |
setTimeout(function() { | |
if ('paused' !== target.style.webkitAnimationPlayState) | |
target.style.webkitAnimationPlayState = 'paused'; | |
if ('paused' !== target.style.MozAnimationPlayState) | |
target.style.MozAnimationPlayState = 'paused'; | |
if ('paused' !== target.style.animationPlayState) | |
target.style.animationPlayState = 'paused'; | |
}, 0); | |
} | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment