views:

234

answers:

2

Hi,

I've found someone with a tutorial showing what I'm essentially after, however, the demo is for a submenu that slides down instead of having the the submenu slide up above the menu item.

Here is the link to the tutorial:

http://www.darkscarab.com/blog/read.php?id=14

Here is the jQuery script it uses:

$(document).ready(function(){
    $(".submenu").slideUp(100, function(){$(".menu_item").css({overflow:'visible'})});
    $(".menu_item").hover(
        function(){
            if($(".submenu", this).queue().length < 2)
                $(".submenu", this).slideDown(500);
        },function(){
            $(".submenu", this).slideUp(500);
        }
    );
});

When I switch out the slideUp for slideDown and vice versa, the thing works well enough sliding up (works even when I don't switch them out!) - but the slide down that is supposed to happen when I exit doesn't really work. It is like the submenu disappears, and then finishes it's downward trajectory next time I hover on it.

Basically, it is all hiccup-y and very unreliable.

Anyone have any brilliant ideas for this novice?

Thank you so much!

+1  A: 

.slideDown shows an element starting at height:0 and then animates the height property to its full value. .slideUp animates the height from its full value down to 0 and then hides the element. In order to create the animation that you want you can't just switch them around since you want slideUp to show instead of hide and vice-versa.

If I were to build what describe, I would abolutely position an element within a relatively positioned element at bottom:0 so that when I animate the height property it would grow from the bottom. Then I would create function mySlideUp() such that it .show()'s the inner element that's initially display:none; height:0 and then .animate({height:'auto'},'slow'). For function mySlideDown() I'd .animate({height:0},'slow') and then hide().

I hope that helps. Wrote it in pseudo-jQuery since you're a novice and it'd be beneficial for you to write it out yourself. Good luck!

mVChr
Thank you for the wonderful explanation, mhr. I can actually understand it :)I will work on it, using the very helpful information you provided, and will post the code for other newbies if/when I get it figured out. I sincerely appreciate your help!
heathwaller
You're welcome, but really, if it works, an upvote and accepted answer is all the thanks I need. ;)
mVChr
Thanks for enlightening me. I will give you proper credit for your help :)This is the code I've come up with (had troubles with some of the height parts suggested in your above code): $(function() { $('#menuli').hover(function(){ if(!$(this).find('a').parent().hasClass('active')) { $(this).find('ul').css({visibility: "visible",display: "none"}).show(500); } },function(){ if(!$(this).find('a').parent().hasClass('active')) { $(this).find('ul:first').hide(500); } }); });Now I get a bit of an animation queue build up - and .stop() doesn't fix it.
heathwaller
A: 

For anyone looking for a navigation menu like the one I was trying to achieve, the following site may be of assistance:

http://www.mrbandfriends.co.uk/

But using mhr's advice, and in looking through how Mr. B coded their navigation, I was finally able to get a workable scroll up navigation with breadcrumbs.

Thank you!

heathwaller
Glad you got it working. It would have been faster if I had just written it out and tested it for you myself, but I'm sure the time you spent will be made up for in the future by what you learned implementing it yourself. Cheers!
mVChr