kodie
7/3/2017 - 7:51 PM

sticky_nav_on_scroll.js

(function($) {
  $(window).scroll(function() {
    var nav = $('#site-navbar');
    var stickyClass = 'navbar-fixed-top';
    var stickyPoint = nav.position().top;
    var scroll = $(this).scrollTop();

    if (nav.attr('data-stickypoint')) {
       stickyPoint = nav.attr('data-stickypoint');
    } else {
       nav.attr('data-stickypoint', stickyPoint);
    }

    if (scroll >= stickyPoint) {
      nav.addClass(stickyClass);
    } else {
      nav.removeClass(stickyClass);
    }
  });
})(jQuery);