Erik
Erik

Reputation: 2530

CSS Keyframes animation go back to initial state

I'm calling an animation like this:

document.getElementById('banner').className = "changeColorToIndigo";

Then I've got the CSS property:

div.changeColorToIndigo {
animation-duration: 1s;
animation-name: changeColorToIndigo;
animation-fill-mode: forwards;
}

And the keyframes animation:

@keyframes changeColorToIndigo {
from {background-color: #00BBD2;}
to {background-color: #3F51B5;}
}

But the animation goes back to it's initial state after the animation has completed, why is that? I've set the fill mode to forwards and specified the to (100%) property.

Upvotes: 2

Views: 4154

Answers (1)

Gust van de Wal
Gust van de Wal

Reputation: 5291

I've put your code in a Fiddle, and it works fine for me

HTML

<div id="banner"></div>

CSS

div{
    height: 40px;
    width: 40px;
    background-color: #00BBD2;
}

div.changeColorToIndigo {
    animation-name: changeColorToIndigo;
    animation-duration: 1s;
    animation-fill-mode: forwards;
}

@keyframes changeColorToIndigo {
    from {background-color: #00BBD2;}
    to {background-color: #3F51B5;}
}

jQuery

$(document).ready(function(){
    $('#banner').addClass('changeColorToIndigo');
})

Upvotes: 1

Related Questions