Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple (?) CSS Animation of Opacity Property

Ok, I don't get this. I've done CSS3 animations before, but for some reason simply animating the opacity isn't working for me today. Am I missing something silly?

CSS:

@-webkit-keyframes fadein {
    from: { opacity: 0; }
    to: { opacity: 1; }
}

@-moz-keyframes fadein {
    from: { opacity: 0; }
    to: { opacity: 1; }
}

@keyframes fadein {
    from: { opacity: 0; }
    to: { opacity: 1; }
}

#foo {
    background-color: green;
    color: white;
    -webkit-animation: fadein 2s ease-in alternate infinite;
    -moz-animation: fadein 2s ease-in alternate infinite;
    animation: fadein 2s ease-in alternate infinite;
}

HTML:

<div id="foo">This is Foo!</div>

I've also posted it as a fiddle: http://jsfiddle.net/NRutman/Lcyvy/

Any help would be appreciated.

Thanks, -Nate

like image 854
Nathan Rutman Avatar asked Jan 21 '13 21:01

Nathan Rutman


2 Answers

You don't need colons after from and to:

@keyframes fadein {
    from { opacity: 0; }
    to { opacity: 1; }
}

http://jsfiddle.net/Lcyvy/6/

like image 52
Pavlo Avatar answered Oct 22 '22 04:10

Pavlo


Change

@keyframes fadein {
    from: { opacity: 0; }
    to: { opacity: 1; }
}

to

@keyframes fadein {
    0%   { opacity: 0; }
    100% { opacity: 1; }
}

DEMO

like image 40
Zoltan Toth Avatar answered Oct 22 '22 04:10

Zoltan Toth