View demo
Today I want to show you, how to create an Apple-style navigation menu with a twist. Although “fancy” and “Apple-style” don’t really go together, I thought that it’s time for something different.
This menu looks very similar to the Apple-style navigation but it reveals some icons when hovering over it. The icons slide out from the top and when the mouse leaves the link, the icon slides back under the link element. This creates a neat “card-shuffle” effect.
The icons used in this tutorial can be found on DryIcons.com. I am not allowed to redistribute the icons under the free license, so I did not include them in the downloadable ZIP file. But you can easily find them here. I did not rename them for the tutorial so that you can easily recreate the navigation without changing the names or the stylesheet.
Ok, let’s get started!
1. The HTML
The markup just consists of a div with an unordered list inside. The list elements contain a span for the icon and the link element:1 2 3 4 5 6 7 8 9 10 11 | < div class = "navigation" > < ul class = "menu" id = "menu" > < li >< span class = "ipod" ></ span >< a href = "" class = "first" >Players</ a ></ li > < li >< span class = "video_camera" ></ span >< a href = "" >Cameras</ a ></ li > < li >< span class = "television" ></ span >< a href = "" >TVs</ a ></ li > < li >< span class = "monitor" ></ span >< a href = "" >Screens</ a ></ li > < li >< span class = "toolbox" ></ span >< a href = "" >Tools</ a ></ li > < li >< span class = "telephone" ></ span >< a href = "" >Phones</ a ></ li > < li >< span class = "print" ></ span >< a href = "" class = "last" >Printers</ a ></ li > </ ul > </ div > |
2. The CSS
The style of the navigation container and the unordered list will be the following:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | .navigation{ position : relative ; margin : 0 auto ; width : 915px ; } ul.menu{ list-style : none ; font-family : "Verdana" , sans-serif ; border-top : 1px solid #bebebe ; margin : 0px ; padding : 0px ; float : left ; } ul.menu li{ float : left ; } |
Now, let’s define the style for the link elements:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | ul.menu li a{ text-decoration : none ; background : #7E7E7E url (../images/bgMenu.png) repeat-x top left ; padding : 15px 0px ; width : 128px ; color : #333333 ; float : left ; text-align : center ; border-right : 1px solid #a1a1a1 ; border-left : 1px solid #e8e8e8 ; font-weight : bold ; font-size : 13px ; -moz-box-shadow: 0 1px 3px #555 ; -webkit-box-shadow: 0 1px 3px #555 ; text-shadow : 0 1px 1px #fff ; } |
The next hover class will be applied using jQuery, since the :hover pseudo class creates an unwanted effect: When the icon slides out it covers the link for a few milliseconds, making the hover style dissapear in that time. That is perceived as a flicker and we will avoid that by defining a class that we will simply add with jQuery when we do the icon slide out effect:
1 2 3 4 5 | ul.menu li a.hover{ background-image : none ; color : #fff ; text-shadow : 0 -1px 1px #000 ; } |
1 2 3 4 5 6 7 8 9 | ul.menu li a.first{ -moz-border-radius: 0px 0px 0px 10px ; -webkit-border-bottom-left-radius: 10px ; border-left : none ; } ul.menu li a.last{ -moz-border-radius: 0px 0px 10px 0px ; -webkit-border-bottom-right-radius: 10px ; } |
1 2 3 4 5 6 7 8 9 10 | ul.menu li span{ width : 64px ; height : 64px ; background-repeat : no-repeat ; background-color : transparent ; position : absolute ; z-index : -1 ; top : 80px ; cursor : pointer ; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | ul.menu li span.ipod{ background-image : url (../icons/ipod.png); left : 33px ; /*128/2 - 32(half of icon) +1 of border*/ } ul.menu li span.video_camera{ background-image : url (../icons/video_camera.png); left : 163px ; /* plus 128 + 2px of border*/ } ul.menu li span.television{ background-image : url (../icons/television.png); left : 293px ; } ul.menu li span.monitor{ background-image : url (../icons/monitor.png); left : 423px ; } ul.menu li span.toolbox{ background-image : url (../icons/toolbox.png); left : 553px ; } ul.menu li span.telephone{ background-image : url (../icons/telephone.png); left : 683px ; } ul.menu li span. print { background-image : url (../icons/ print .png); left : 813px ; } |
3. The JavaScript
First, we want to create the effect of the icons dissapearing in a stair-like fashion and then we will define the hover function for the list elements:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | $( function () { var d=1000; $( '#menu span' ).each( function (){ $( this ).stop().animate({ 'top' : '-17px' },d+=250); }); $( '#menu > li' ).hover( function () { var $ this = $( this ); $( 'a' ,$ this ).addClass( 'hover' ); $( 'span' ,$ this ).stop().animate({ 'top' : '40px' },300).css({ 'zIndex' : '10' }); }, function () { var $ this = $( this ); $( 'a' ,$ this ).removeClass( 'hover' ); $( 'span' ,$ this ).stop().animate({ 'top' : '-17px' },800).css({ 'zIndex' : '-1' }); } ); }); |
And that’s all!
I hope you like and enjoy it!
0 comments:
Post a Comment