Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sticky NavBar onScroll?

I'm currently building a site for myself, and I found this really awesome effect on multiple sites where the navbar is below an image, but when you scroll past it, it sticks to the top.

Example

How can I achieve this? Also, how can I achieve an effect similar to the one on this website with a similar navbar style?

like image 893
Kevin Haube Avatar asked Dec 12 '22 06:12

Kevin Haube


1 Answers

Here is what @Matthew was talking about:

Check this fiddle http://jsfiddle.net/luckmattos/yp8HK/1/

JQUERY

var num = 200; //number of pixels before modifying styles

$(window).bind('scroll', function () {
    if ($(window).scrollTop() > num) {
        $('.menu').addClass('fixed');
    } else {
        $('.menu').removeClass('fixed');
    }
});

Hope it helps, I used bootstrap navbar.

like image 99
Mattos Avatar answered Dec 21 '22 10:12

Mattos