I've hit a roadblock while attempting to trigger a CSS animation.
Here's my CSS:
h3[id="balance-desktop"]{
color: black;
-webkit-animation-name: gogreen;
-webkit-animation-duration: 2s;
animation-name: gogreen;
animation-duration: 2s
}
/* Safari 4.0 - 8.0 */
@-webkit-keyframes gogreen {
from {color: black;}
to {color: limegreen;}
from{color: limegreen;}
to{color: black;}
}
/* Standard syntax */
@keyframes gogreen {
from {color: black;}
to {color: limegreen;}
from{color: limegreen;}
to{color: black;}
}
It's a simple animation that changes the color of an h3[id=balance-desktop]
element.
The animation works when the page loads. I'm trying to make it work when I call my JavaScript function, but so far, no success.
Attempt #1:
function showGreenAnimation(){
var test = document.getElementById("balance-desktop");
test.style.webkitAnimationName = 'gogreen';
test.style.webkitAnimationDuration = '4s';
}
Attempt #2:
function showGreenAnimation(){
document.getElementById("balance-desktop").style.webkitAnimationName = "";
setTimeout(function ()
{
document.getElementById("balance-desktop").style.webkitAnimationName = "gogreen";
}, 0);
}
I've tried all the solutions recommended on How to activate a CSS3 (webkit) animation using JavaScript?, but none have worked for me.
Is there something incorrect in my code?