I have made a beginner's attempt at making a vertical navigation menu of which the parents open on hover:
HTML
<ul class="pages-list"> <li class="page_item">Grand Parent 1 <ul class="first-children"> <li class="page_item">Parent 1</li> <li class="page_item">Parent 2 (hover me) <ul class="children"> <li class="page_item">Child 1</li> <li class="page_item">Child 2 <ul class="children"> <li class="page_item">Grandchild 1</li> <li class="page_item">Grandchild 2</li> <li class="page_item">Grandchild 3</li> </ul> </li> <li class="page_item">Child 3</li> </ul> </li> <li class="page_item">Parent 3 (hover me) <ul class="children"> <li class="page_item">Child 1</li> <li class="page_item">Child 2</li> <li class="page_item">Child 3</li> </ul> </li> <li class="page_item">Parent 4</li> </ul> </li> </ul> CSS
.first-children > .page_item > .children.open { height:auto; -webkit-transition: all 1s ease; -moz-transition: all 1s ease; -o-transition: height 1s ease; -ms-transition: height 1s ease; transition: all 1s ease; } .first-children > .page_item > .children { height: 0; overflow:hidden; -webkit-transition: all 1s ease; -moz-transition: all 1s ease; -o-transition: height 1s ease; -ms-transition: height 1s ease; transition: all 1s ease; } (tried the transition on both all and height)
jQuery
$(document).ready(function(){ $(".first-children > .page_item").hover(function(){ $(this).find("> .children").toggleClass("open"); }); }); Result http://jsfiddle.net/senlin/DVUZ5/
Now what I would like to have is to use a CSS transition when the children receive the class open
Is that even possible with height:0 and height: auto?
If not how do I need to alter the code so the transition effect becomes possible? I tried it on both "all" and "height", but that doesn't do anything.