0

I have the following css for my drop down menu in my banner:

#nav-menu li a
{
    background-image:url('../images/menu_background.png');  
    background-repeat:repeat-x;
    background-position: left top;
    height: 35px;
}


#nav-menu li a:hover
{
    background-image:url('../images/menu_background_hover.png');  
    background-repeat:repeat-x;
    background-position: left top;
    height: 35px;

}

It works fine, except that I would like some animation effect when I hover over the <li> tag. Currently, it just replaces the background colour of the <li> when i hover over it.

I tried the example code below which changes the margin-left of the li tag but I do not know how to animate the css transition on hover:

$j(document).ready(function () {

    //When mouse rolls over
    $j("#nav-menu li").hover(function () {

        $j(this).filter(':not(:animated)').animate({
            marginLeft: '9px'
        }, 'slow');
    },

    function () {
        $j(this).animate({
            marginLeft: '0px'
        }, 'slow');
    });

});

Thanks a lot for any suggestion.

Anthony Simmon
  • 1,579
  • 12
  • 26
Kim
  • 2,070
  • 5
  • 33
  • 46

2 Answers2

1

A quote from this post,

Blockquote I guess you would have to work around this by not using genuine background-images, but div elements containing the image, positioned using position: absolute (or fixed) and z-index for stacking. You would then animate those divs. Blockquote

Community
  • 1
  • 1
Vivek S
  • 5,384
  • 8
  • 51
  • 72
0

I got this working by removing the j after the $ in the variable names.

Fiddle: http://jsfiddle.net/XjxBj/

$(document).ready(function () {
    //When mouse rolls over
    $("#nav-menu li").hover(function () {
        $(this).filter(':not(:animated)').animate({
            marginLeft: '9px'
        }, 'slow');
    },

    function () {
        $(this).animate({
            marginLeft: '0px'
        }, 'slow');
    });
});​
Jørgen R
  • 10,568
  • 7
  • 42
  • 59