Animate Height
Also includes animating with psuedo element.
by Matthew Day
HTML
<div class="parent">
<div class="title">Title</div>
<ul class="child">
<li class="first">John</li>
<li>Peter</li>
<li>James</li>
</ul>
</div>
CSS
* {
box-sizing: border-box;
margin: 0;
padding: 0;
background: gray;
color: white;
font-family: arial;
text-transform: uppercase;
}
.parent {
width: 200px;
margin: 20px auto 0;
}
.title {
padding: 4px;
border: 1px solid rgba(255,255,255,.2);
text-align: center;
}
.child {
height: 0;
max-height: 0;
background: black;
overflow: hidden;
text-align: center;
-webkit-transition: all 500ms cubic-bezier(1.000, 0.000, 0.005, 1.005);
}
.child.active {
height: 500px;
max-height: 500px;
}
li {
margin-top: 20px;
padding: 2px 0 2px 20px;
width: 100%;
list-style-type: none;
opacity: 1;
-webkit-transition: all 800ms ease-in-out;
text-align: left;
background: inherit;
color: #1391ff;
letter-spacing: 4px;
}
li.active {
margin-top: 10px;
opacity: 1;
}
.first {
position: relative;
color: white;
}
.first:before {
position: absolute;
content: '|';
top: 0;
left: -5px;
transition: all 400ms cubic-bezier(0.570, -0.540, 0.450, 1.570);
}
.first.active:before {
left: 5px;
}
JavaScript
$('.title').click(function() {
$('.child').toggleClass('active');
$('li').toggleClass('active');
});