user1148967
user1148967

Reputation: 23

How to make a floating top menu?

I want to achieve a menu something like: http://craigsworks.com/projects/qtip2/tutorials/

Everytime you scroll down on the page , a specific div menu always stays on top.

Any help or tutorial link page, is well appreciated.

Here is the screenshots:

http://www.pokoot.com/menu.png

www.pokoot.com/menu2.png

Upvotes: 0

Views: 1235

Answers (1)

Jake Stoeffler
Jake Stoeffler

Reputation: 2885

You can fix the position of an element using CSS. For example,

#floatingMenu {
    position: fixed;
    top: 0px;
}

would keep #floatingMenu at the top of the page at all times. Then, if you want to mimic theirs where the fixed-position menu bar doesn't show up until you've scrolled past some point on the page, you could do something like the following:

$docBody = $(document.body);
$docBody.scroll( function() {
    // replace 100 with whatever the non-floating menu bar's distance from the top of the page is
    if ($docBody.scrollTop() < 100) { 
        $('#floatingMenu ').hide();
    } else {
        $('#floatingMenu ').show();
    }
} );

Upvotes: 1

Related Questions