Hi,
I currently have a drop-line horizontal menu using an unordered list with the following HTML markup:
<div class="menu">
<ul>
<li><a class="tier1" href="#">Top Link 1</a></li>
<li>
<a class="tier1" href="#">Top Link 2</a>
<ul>
<li><a href="#">Sub Link 1</a></li>
<li><a href="#">Sub Link 2</a></li>
<li><a href="#">Sub Link 3</a></li>
</ul>
</li>
<li><a class="tier1" href="#">Top Link 3</a></li>
</ul>
</div>
The CSS is far too lengthy to paste in here, but it follows the same structure that I've been using for ages here from CSS Menu Maker - the only difference is that for the sub-menu list items, I have them displayed "inline" with their widths set to "auto" and a bit of left and right padding, and every Top Link menu item with a class of "tier1" uses CSS Sprites. The jQuery is where I am having an issue. Ordinarily, this would be the approach to take:
function animateMenu() {
$('.menu li a.tier1').css({backgroundPosition:'0 -60px'});
$('.menu li a.tier1').hover(
function() {
$(this).stop(true, true).animate({backgroundPosition:'0 0'},{duration:400})
.next('ul').css({display:'none'}).stop(true, true).delay(200).slideDown(400);
},
function() {
$(this).stop(true, true).animate({backgroundPosition:'0 -60px'},{duration:250})
.next('ul').stop(true, true).slideUp(400);
}
);
}
Whilst this method works, and visually does what I want it to do, the SubMenu obviously slides back up when I mouseout off the Top Link items. My only workaround for this was to break it into two separate functions:
function animateTopMenu() {
$('.menu li a.tier1').css({backgroundPosition:'0 -60px'});
$('.menu li a.tier1').hover(
function() {
$(this).stop(true, true).animate({backgroundPosition:'0 0'},{duration:400});
},
function() {
$(this).stop(true, true).animate({backgroundPosition:'0 -60px'},{duration:250});
}
);
}
function animateSubMenu(){
$('.menu li').hover(
function() {
$(this).find('ul:first').css({display:'none'}).stop(true, true).delay(200).slideDown(400);
},
function() {
$(this).find('ul:first').stop(true, true).slideUp(400);
}
);
}
This helps me keep my SubMenu items hover-able when I mouseout off the Top Link, but what I would ideally like to do is retain the hovered background appearance of the Top Links when I hover over the submenu items, and only revert (and animate) to the normal state once the mouse has moved off either the submenu or the top Link itme itself. This is where I am having difficulties. I could add and remove a class with CSS "background-positon: 0 0 !important" but then the animation effect is lost.
I'm sorry for the lengthy question, but just wanted to provide as much as possible to get your help!
Thank you!! -Shalan