apamphilon

Sticky nav

var num = 175; //number of pixels before modifying styles
var fixedElement = $('#mastnav');
var responsiveBreakpoint = 768;

$(window).bind('scroll', function () {
    if ( $(window).width() >= responsiveBreakpoint ) {

        if ($(window).scrollTop() > num) {
            fixedElement.addClass('fixed');
        } else {
            fixedElement.removeClass('fixed');
        }
    }
});

// stops stickynav on responsive below responsiveBreakpoint
if ( $(window).width() < responsiveBreakpoint ) {
    fixedElement.removeClass('fixed');
}

$(window).resize(function() {
    if ( $(window).width() < responsiveBreakpoint ) {
        fixedElement.removeClass('fixed');
    }
});

Comments: