JSFiddle - React, Tailwind, and code Playground
by lottikarotti
HTML
<div id="wrapper">
<div id="nav">
<ul>
<li><a id="home" href="#">home</a></li>
<li><a id="work" href="#">work</a></li>
<li><a id="about" href="#">about</a></li>
<li><a id="contact" href="#">contact</a></li>
</ul>
<div class="clear"></div>
<div class="bar">
<ul id="ulhome">
<li><a href="#">ulhome1</a></li>
<li><a href="#">ulhome2</a></li>
<li><a href="#">ulhome3</a></li>
</ul>
<ul id="ulwork">
<li><a href="#">ulwork1</a></li>
<li><a href="#">ulwork2</a></li>
<li><a href="#">ulwork3</a></li>
</ul>
<ul id="ulabout">
<li><a href="#">ulabout1</a></li>
<li><a href="#">ulabout2</a></li>
<li><a href="#">ulabout3</a></li>
</ul>
<ul id="ulcontact">
<li><a href="#">ulcontact1</a></li>
<li><a href="#">ulcontact2</a></li>
<li><a href="#">ulcontact3</a></li>
</ul>
</div>
</div>
</div>
CSS
* {
padding: 0 ;
margin: 0 ;
border: 0 none ;
}
html, body {
width: 100% ;
height: 100% ;
}
#wrapper {
width: 100% ;
height: 100% ;
}
.clear {
clear: both ;
}
ul {
list-style: none ;
}
ul li {
display: block ;
float: left ;
}
#nav > ul:first-child {
margin-left: 100px ;
}
#nav > ul li:hover {
background-color: #EAEAEA ;
}
#nav > ul li a {
display: block ;
padding: 10px ;
text-decoration: none ;
color: #000 ;
}
.bar {
padding-left: 100px ;
/*width: 100% ;*/
height: 0 ;
background-color: #333 ;
}
.bar ul li a {
display: block ;
padding: 10px ;
text-decoration: none ;
color: #FFF ;
}
.bar ul li a:hover {
background-color: #444 ;
}
JavaScript
( function( $ ) {
$.fn.menufiy= function( ) {
this.each( function( ) {
var t = $(this) ;
t.data( 'acomplete', false ) ;
t.data( 'aclose', false ) ;
t.children( 'ul' ).mouseenter( function( ) {
t.children( '.bar' ).stop( ).animate( { 'height' : '40px' }, 400, function( ) {
t.data( 'acomplete', true ) ;
if( t.data( 'aclose' ) ) {
t.children( '.bar' ).stop( ).delay( 400 ).animate( { 'height' : '0px' }, 400 ) ;
t.children( '.bar' ).stop( ).delay( 400 ).children( 'ul' ).hide( ) ;
t.data( 'acomplete', false ) ;
t.data( 'aclose', false ) ;
}
} ) ;
} ) ;
t.mouseenter( function( ) {
t.data( 'aclose', false ) ;
} ) ;
t.mouseleave( function( ) {
if( t.data( 'acomplete' ) ) {
t.children( '.bar' ).stop( ).delay( 400 ).animate( { 'height' : '0px' }, 400 ) ;
t.children( '.bar' ).stop( ).delay( 400 ).children( 'ul' ).hide( ) ;
t.data( 'acomplete', false ) ;
t.data( 'aclose', false ) ;
} else {
t.data( 'aclose', true ) ;
}
} ) ;
t.children( 'ul' ).children( 'li' ).children( 'a' ).mouseenter( function( ) {
t.children( 'ul' ).children( 'li' ).children( 'a' ).css( { 'background-color' : '#FFF' } ) ;
$(this).css( { 'background-color' : '#EAEAEA' } ) ;
t.children( '.bar' ).children( 'ul' ).hide( ) ;
t.children( '.bar' ).children( 'ul#ul' + $(this).attr( 'id' ) ).show( ) ;
} ) ;
} )...