Mario Parra Mario Parra - 1 year ago 126
Javascript Question

Make nav bar sticky


I have a nav bar on my website ( - 'menu-secondary-wrap') and I'm trying to make it stay at the top of the page when the user scrolls down.

I've tested several jQuery samples (such as, but they always come with their own CSS, which seems to interfere with what I'm already using.

What's the easiest/best way to do this for an existing class?


Answer Source

Try this script

jQuery(document).scroll(function() {
    if (jQuery(this).scrollTop() > 175) {
           'position': 'fixed',
           'top': '0',
           'width': '950px'
    else {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download