function initializeNav() {
        var $nav = $('.nav');
        
        function navStickToTop() {
            if ($window.outerWidth() > 768) {
                var navOffsetTop = $nav.offset().top;
                
                $nav.addClass('relative');
            
                if ($window.scrollTop() > navOffsetTop) {
                    $nav.removeClass('relative');
                }
                    
                $(window).on('scroll', function() {
                    if ($window.scrollTop() < navOffsetTop) {
                        $nav.addClass('relative');
                    } else {
                        $nav.removeClass('relative');
                    }
                });
            }
        }
        
        navStickToTop();
        
        // Offsets may change on resizing window
        $(window).resize(function() {
            
            navStickToTop();
        });
    }
// Stick nav to top after scroll threshold
Stick nav to top after scroll threshold
Stick nav to top after scroll threshold
function initializeNav() {
        var $nav = $('.nav');
        function navStickToTop() {
            if ($window.outerWidth() > 768) {
                var navOffsetTop = $nav.offset().top;
                $nav.addClass('relative');
                if ($window.scrollTop() > navOffsetTop) {
                    $nav.removeClass('relative');
                }
                $(window).on('scroll', function() {
                    if ($window.scrollTop() < navOffsetTop) {
                        $nav.addClass('relative');
                    } else {
                        $nav.removeClass('relative');
                    }
                });
            }
        }
        navStickToTop();
        $(window).resize(function() {
            navStickToTop();
        });
    }
function initializeNav ( ) { var $nav = $ ( '.nav' ) ; function navStickToTop ( ) { if ( $window . outerWidth ( ) > 768 ) { var navOffsetTop = $nav . offset ( ) . top ; $nav . addClass ( 'relative' ) ; if ( $window . scrollTop ( ) > navOffsetTop ) { $nav . removeClass ( 'relative' ) ; } $ ( window ) . on ( 'scroll' , function ( ) { if ( $window . scrollTop ( ) < navOffsetTop ) { $nav . addClass ( 'relative' ) ; } else { $nav . removeClass ( 'relative' ) ; } } ) ; } } navStickToTop ( ) ; $ ( window ) . resize ( function ( ) { navStickToTop ( ) ; } ) ; }
Stick nav to top after scroll threshold
Stick nav to top after scroll threshold
// Offsets may change on resizing window