Trying to animate in CSS3 margins. Which this site seems to say you can, but it's not working for me.
Here is a jsFiddle: http://jsfiddle.net/ybh0thp9/3/ (Click on a section to see animation toggle).
Here is my CSS:
.section{
display: block;
animation: fadeIn .5s ease, margin-top .5s ease, margin-bottom .5s ease;
}
.section.open {
margin: 20px 0;
}
I actually have 3 animations. 1 for a simple initial fadeIn
on initial load, then the 2 others for the margin
animation on click. I've also just tried margin
instead of the top and bottom but still no sign of it working.
You don't need keyframes for this: http://jsfiddle.net/BramVanroy/ybh0thp9/7/
You need to add the transition property to the base element that you wish to animate.
You also mentioned that you wanted opacity change, but I don't see how that's possible considering you only have a single element without children. I mean: you can't click on the element if it's hidden.
What you can do, though, is add opacity to the whole thing: http://jsfiddle.net/BramVanroy/ybh0thp9/9/
Or even prettier, with a transformation:
http://jsfiddle.net/BramVanroy/ybh0thp9/10/
Per comment, you want to fade in the elements on page load. We can do that by adding a class
init
.http://jsfiddle.net/BramVanroy/ybh0thp9/12/
With keyframes: http://jsfiddle.net/BramVanroy/ybh0thp9/14/
To create animations witch CSS3 you need to:
1 - Create a class with animation atribute, to work in some browsers you need to put prefixes: -webkit-, -o-, -moz-. 2 - Create animation keyframes
see the example: