I'm trying to make a show/ hide menu button for mobile devices using media queries.
I'm aware that CSS3 on mobile is faster, most of the time, on mobile compared to using jQuery animate because of hardware acceleration, hence I want to use this method.
I need a smooth, 0.5s CSS3 animation from 0px to whatever height the container is.
What I'd like to do - or the logic I'd thought of so far - is when clicking this UI icon, you toggle the height of the .nav>ul from 0px to auto.
I've tried using transition: height and adding a class to the required bit using jQuery, but I cannot figure out how to apply a CSS£ transform / transition to the height and get it to smoothly toggle the height, and I'm now stuck. Don't even know what to Google for (have tried, trust me!).
Here's a working JSFiddle: http://jsfiddle.net/3v47n/ - the small grey 20x20 icon is the trigger.
My jQuery:
$('.nav span').on('click',function(){
$('.nav ul').addClass('animateHeight')
});
And my CSS:
.nav {
min-height: 60px;
}
.nav ul {
height: 0;
overflow: hidden;
transition: height 0.5s ease;
}
.nav ul.animateHeight {
height: auto;
max-height: 9999px;
}