You do not need keyframes for this: http://jsfiddle.net/BramVanroy/ybh0thp9/7/
transition: margin 700ms;
You need to add the transition property to the base element that you want to animate.
You also mentioned that you want to change the opacity, but I donβt see how this is possible, given that you have only one element without children. I mean: you cannot click on an element if it is hidden.
However, you can add opacity to everything: http://jsfiddle.net/BramVanroy/ybh0thp9/9/
Or even prettier, with the conversion:
http://jsfiddle.net/BramVanroy/ybh0thp9/10/
.section { margin: 0; opacity: 0.7; transform: scale(0.85); transition: all 700ms; } .section.open { margin: 20px 0; opacity: 1; transform: scale(1); }
In one comment, you want to fade in page load elements. We can do this by adding the init class.
http://jsfiddle.net/BramVanroy/ybh0thp9/12/
$(".section").addClass("init");
With keyframes: http://jsfiddle.net/BramVanroy/ybh0thp9/14/
@-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; } } -webkit-animation: fadeIn 1.5s ease; -moz-animation: fadeIn 1.5s ease; animation: fadeIn 1.5s ease;
source share