Skip to content

Instantly share code, notes, and snippets.

@vv3d0x
Created March 24, 2017 15:34
Show Gist options
  • Select an option

  • Save vv3d0x/980eb3a1dae888aab77b16114bd03c1f to your computer and use it in GitHub Desktop.

Select an option

Save vv3d0x/980eb3a1dae888aab77b16114bd03c1f to your computer and use it in GitHub Desktop.
(function ($, window, document) {
'use strict';
const SC_UP = (1 << 1);
const SC_DOWN = (1 << 0);
var $navbar = $("#nav-menu"),
$offset = $navbar.offset().top;
var lock = 0;
$(document).scroll(function() {
var scrollTop = $(this).scrollTop();
if (scrollTop > $offset) {
lock |= SC_DOWN;
if (lock & SC_UP) {
console.log('fixed');
lock &= ~SC_UP;
$navbar.removeClass('navbar-static-top').addClass("navbar-fixed-top");
}
} else if (scrollTop <= $offset) {
lock |= SC_UP;
if (lock & SC_DOWN) {
console.log('static');
lock &= ~SC_DOWN;
$navbar.removeClass('navbar-fixed-top').addClass("navbar-static-top");
}
}
$navbar.clearQueue();
});
})(jQuery, window, document);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment