Submit your widget

an Animated Navigation with jQuery

Created 12 years ago   Views 12054   downloads 2280    Author devirtuoso
an Animated Navigation with jQuery
View DemoDownload
Share |

The idea is to build a menu that just displays icons, when the user rolls over each icon the text will appear below. The icon will also have a roll over state to help highlight the menu item.

Getting Started

First thing we are going to do is setup a basic skeleton of the HTML file.  This will import jQuery, and setup the basic structure of the navigation.  If you don’t have the jQuery library you can get it at jQuery’s website.

    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
    <title>jQuery Navigation</title>

    <div id="menuBar">
            <li><a href="#" id="Home">Home</a></li>
            <li><a href="#" id="About">About</a></li>
            <li><a href="#" id="Gallery">Gallery</a></li>
            <li><a href="#" id="Contact">Contact</a></li>

<script type="text/javascript" src=""></script>



The Images

Your going to have 3 images. One being the background that the icons sit on. Two being the actual icons, and three being the icons roll over state.  Here is a look at the images we’ll be using.





Icons Over State

The background image will be applied to the div wrapping your menu list, and the icons and icon’s over state image will be sliced up and applied to each navigation element.  You could probably get a little more creative with your imagery than I did, but it will work for our purposes.



The idea behind the CSS is to layout the navigation so it looks nice, handle the roll over state of each menu item, and prepare the navigation for animation.

The div wrapper holds the background image, each of our menu items will then have their own background images (icons).  We will also add a top padding to each menu item so it pushes the text below the bottom of our wrapper. The important thing here is that we gave our div wrapper an overflow of hidden, this will hide the text of the menu items for us.

/* Div Wrapper */
    /* Hide text that goes beyond
       the bottom of the wrapper */
    /* Give wrapper background image */
    background: transparent url(bar.jpg) no-repeat scroll left top;
    /* Center menu on page and give it a border */
    margin:0 auto;
    border:10px solid #111;

#menuBar ul{
    /* Center menu inside wrapper */
    margin:0 auto;
    /* Get rid of bullets */
    list-style-type: none;

#menuBar ul li{
    /* Make menu horizontal */
    /* Add spacing between menu items */

#menuBar a{
    /* Give each menu item a background image */
    background: transparent url(logos.jpg) no-repeat scroll left top;

    /* Push text down below bottom of wrapper*/
    /* Beautify Text*/
    font-family: Arial, "MS Trebuchet", sans-serif;
    text-decoration: none;

#menuBar a:hover{
    /* change background image for rollover state */

/* Position each background image accordingly
   to display icons */
#menuBar a#Home{
    background-position:-67px top;
#menuBar a#About{
    background-position:-166px top;
#menuBar a#Gallery{
    background-position:-266px top;
#menuBar a#Contact{
    background-position:-373px top;


Animating the Menu Text

Now comes the jQuery, what we plan to do is simply animated the top padding of each menu item on mouse over and on mouse out.

//Make sure the document is ready.
$(document).ready(function() {
    //Mouse Over function
        // Capture the id of the element that
        // is current rolled over.
        var selected = "#"+$(this).attr("id");
        //then animate it's top padding
        $(selected).animate({paddingTop:"78px"}, 100);
    //Mouse Out Function
        // Capture the id of the element that
        // is current rolled out.
        var selected = "#"+$(this).attr("id");
        //then animate it's top padding
        $(selected).animate({paddingTop:"100px"}, 100);


That’s It