emulate youtube show more - jQuery
http://stackoverflow.com/questions/11595394/how-do-i-reproduce-youtubes-show-more-functionality/11597184#11597184
by thebabydino
HTML
<div class="info-wrapper">
<a href="#" tabindex="1" class="more">Show more</a>
<a href="#" tabindex="1" class="less">Show less</a>
<div class="info">
<p>Bear claw oat cake marshmallow. Sweet jujubes lemon drops biscuit sweet
roll. Gingerbread applicake apple pie cheesecake candy bonbon. Sweet sugar
plum dessert icing gummies.</p>
<p>Bear claw oat cake marshmallow. Sweet jujubes lemon drops biscuit sweet
roll. Gingerbread applicake apple pie cheesecake candy bonbon. Sweet sugar
plum dessert icing gummies.</p>
<p>Bear claw oat cake marshmallow. Sweet jujubes lemon drops biscuit sweet
roll. Gingerbread applicake apple pie cheesecake candy bonbon. Sweet sugar
plum dessert icing gummies.</p>
<!--[if lte IE 9]><div class="aftershadow"></div><![endif]-->
</div>
</div>
CSS
body {
background: #ccc;
}
.info-wrapper {
height: auto;
width: 500px;
margin: 0 auto;
padding: 0 0 2em 0;
position: relative;
}
.info {
height: 120px;
padding: .5em 0;
border-bottom: solid 1px #fff;
border-radius: 0 0 1em 1em;
overflow: hidden;
position: relative;
}
p { margin: 1em; }
.info:after, .aftershadow {
bottom: 0;
width: 100%;
height: 3em;
border-radius: 0 0 1em 1em;
position: absolute;
background: -webkit-linear-gradient(rgba(192,192,192,0), #ccc);
background: -moz-linear-gradient(rgba(192,192,192,0), #ccc);
background: -ms-linear-gradient(rgba(192,192,192,0), #ccc);
background: -o-linear-gradient(rgba(192,192,192,0), #ccc);
background: linear-gradient(rgba(192,192,192,0), #ccc);
content: '';
}
.aftershadow {
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#00cccccc, endColorstr=#ffcccccc);
}
.info-wrapper a {
left: 50%;
bottom: 1.5em;
width: 9em;
height: 1.25em;
margin: -.1em 0 .35em -4.5em;
border-bottom: solid 1px #fff;
border-radius: 0 0 1em 1em;
display: block;
overflow: hidden;
position: absolute;
color: #000;
font: 700 .67em/1.25em Arial;
text-align: center;
text-decoration: none;
text-shadow: 0 1px 0 #fff;
cursor: pointer;
}
.info-wrapper a:focus { outline: none; }
.info-wrapper .less { margin-top: -1.5em; opacity: 0; z-index: -1; }
JavaScript
$('.more').click(function(){
$(this).animate({'opacity': '0'}, 1000);
$('.less').animate({
'opacity': '1',
'z-index': '1'
}, 1000);
$('.info').animate({'height': '15em'}, 1000);
});
$('.less').click(function(){
$(this).animate({
'opacity': '0',
'z-index': '-1'
}, 1000);
$('.more').animate({'opacity': '1'}, 1000);
$('.info').animate({'height': '120px'}, 1000);
});