In JavaScript it's easy to get the name and properties of CSS animations applied to an element:
var animName = element.style.webkitAnimationName;
// element.style.mozAnimationName
// etc...
But is there a way to read out or even change the CSS keyframes for animations?
Thanks to the comments I was able to get to this solution:
var allStyles = document.styleSheets;
var keyframeType = window.CSSRule.WEBKIT_KEYFRAMES_RULE || window.CSSRule.KEYFRAMES_RULE;
for (var declaration in allStyles) {
if (allStyles.hasOwnProperty(declaration)) {
var ruleSet = allStyles[declaration].cssRules;
for (var rule in ruleSet) {
if (ruleSet.hasOwnProperty(rule)) {
var currentRule = ruleSet[rule];
if (currentRule.type == keyframeType) {
console.log(currentRule);
}
}
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With