S
S
Sergey Kuznetsov2015-11-23 23:01:31
Bootstrap
Sergey Kuznetsov, 2015-11-23 23:01:31

How to make the top menu scroll to the top of the site and be fixed there?

The menu should be about 100px from the top. Bootstrap has a "navbar-fixed-top" class that hard-fixes the menu on top. How to make the menu, when scrolling, first be UNFIXED, and when it touches the top, it remains there, that is, it becomes FIXED? Thank you!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
Ilya, 2015-11-23
@CheapThailand

When scrolling the site page (scroll event), check the current position of the slider. If the page is scrolled more than 100px, assign the necessary Bootstrap class to the menu container, if less than - remove the corresponding class.
Please note: when fixing the menu, it is necessary to create a block in its original place in the body of the page that matches the size of the menu. This will avoid a jump when removing the menu from the usual flow of elements on the page.
If not tied to Bootstrap, there are plugins that allow you to fix the menu on scroll. Look.

A
Alexander Taratin, 2015-11-23
@Taraflex

Make the menu fixed right away, but move the content down by the height of the menu via css.
An example of how to make anchors work correctly.
https://jsfiddle.net/QW01_01/4rav53j6/1/

S
Sergey Kuznetsov, 2015-11-24
@CheapThailand

Thanks to all!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question