Created
March 24, 2017 15:34
-
-
Save vv3d0x/980eb3a1dae888aab77b16114bd03c1f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (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