Created
December 14, 2014 17:47
-
-
Save mrofi/5146a8e0a2a76fb95221 to your computer and use it in GitHub Desktop.
This function can make navbar become fixed-top navbar when user do scrolling and top of the navbar meets the top border of browser.
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
| jQuery(function() { | |
| window.magellan = function() { | |
| obj = $('.magellan'); | |
| pos = obj.offset().top; | |
| pos2 = obj.next().offset().top-obj.innerHeight(); | |
| $(window).scroll(function() { | |
| if (pos < $(this).scrollTop() && !obj.hasClass('navbar-fixed-top')) return obj.addClass('navbar-fixed-top'); | |
| if (pos2 > $(this).scrollTop()) return obj.removeClass('navbar-fixed-top'); | |
| }); | |
| } | |
| }) | |
| // Run with call : window.magellan() and don't forget to add class "magellan" into navbar that you want to work with. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment