JSFiddle - React, Tailwind, and code Playground
HTML
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<div class="everything">
<div class="menu">
<div class="d1 active" data-content="home"></div>
<div class="d2" data-content="about"></div>
<div class="d3" data-content="contact"></div>
</div>
<div class="main">
<div class="home">This is some example content.</div>
<div class="about">This is just some sample text that's being used to demonstrate animating the height when content changes.
<br>This is just some sample text that's being used to demonstrate animating the height when content changes.
<br>This is just some sample text that's being used to demonstrate animating the height when content changes.
<br>This is just some sample text that's being used to demonstrate animating the height when content changes.
<br>This is just some sample text that's being used to demonstrate animating the height when content changes.
<br>This is just some sample text that's being used to demonstrate animating the height when content changes.
<br>This is just some sample text that's being used to demonstrate animating the height when content changes.
<br>This is just some sample text that's being used to demonstrate animating the height when content changes.
<br>This is just some sample text that's being used to demonstrate animating the height when content changes.
<br>This is just some sample text that's being used to demonstrate animating the height when content changes.
<br>This is just some sample text that's being used to demonstrate animating the height when content changes.
<br>This is just some sample text that's being used to demonstrate animating the height when content changes.
<br>This is just some sample text that's being used to demonstrate animating the height when content changes.
...
CSS
body {
background: -webkit-gradient(linear, left top, right bottom, from(rgba(237, 182, 165, 1)), to(rgba(126, 86, 112, 1)), color-stop(.7, #cc8e85));
background: -moz-linear-gradient(rgba(237, 182, 165, 1) 0%, rgba(126, 86, 112, 1) 100%);
width: 100%;
height: 100%;
overflow: hidden;
z-index: 0;
}
.everything {
position: absolute;
left: 0px;
top: 0px;
width: 102%;
height: 100%;
background: url(images/transparent_noise.png);
overflow-y: scroll;
z-index: 1;
}
.menu {
position: relative;
left: 0;
right: 0;
margin: auto;
top: 50px;
width: 308px;
height: 50px;
z-index: 999;
}
.d1, .d2, .d3 {
position: relative;
width: 100px;
height: 50px;
background-color: white;
margin-bottom: 5px;
opacity: .5;
display: inline-block;
-webkit-transition: all 0.5s ease;
-moz-transition: all 0.5s ease;
-o-transition: all 0.5s ease;
transition: all 0.5s ease;
}
.d1:hover, .d2:hover, .d3:hover {
opacity: 1;
}
.active {
opacity: 1;
}
.main {
position: relative;
left: 0;
right: 0;
margin: auto;
top: 100px;
width: 900px;
height: 0;
background-color: white;
box-shadow: 0px 0px 1px gray;
z-index: 2;
}
.home {
position: relative;
left: 0px;
top: 0px;
width: 900px;
overflow: visible;
z-index: 3;
display: none;
}
.about {
position: relative;
left: 0px;
top: 0px;
width: 900px;
overflow: visible;
z-index: 3;
display: none;
}
.contact {
position: relative;
left: 0px;
top: 0px;
width: 900px;
overflow: visible;
z-index: 3;
display: none;
}
.hide {
display: none;
}
.footer {
position: relative;
left: 0;
right: 0;
margin: auto;
top: 110px;
width: 900px;
height: 50px;
border: 1px dashed green;
z-index: 999;
}
JavaScript
$(document).ready(function () {
// removed height: 0 from children in stylesheet, set to display: none instead
// set height to 0 on .main instead
// click handler for menu items
$('.menu > div').click(function () {
$('.menu > div').removeClass('active');
$(this).addClass('active');
// get content associated w/ this menu item
// the class is in data-content attribute of the menu item
var contentDiv = $('.main').find('.' + $(this).data('content'));
var contentHeight = contentDiv.height();
if (!contentDiv.is(':visible')) {
$('.main > div:visible').stop().fadeOut('slow', function () {
$('.main').stop().delay(500).animate({
height: contentHeight + 'px'
}, 500, function () {
contentDiv.stop().fadeIn('slow');
});
});
}
});
// init home
$(".main").height($('.main > .home').height());
$('.home').show();
});