Skip to content

Instantly share code, notes, and snippets.

@jbuncle
Last active November 25, 2020 16:07
Show Gist options
  • Save jbuncle/dd648943136f0041f0432ee86b180c6e to your computer and use it in GitHub Desktop.
Save jbuncle/dd648943136f0041f0432ee86b180c6e to your computer and use it in GitHub Desktop.
jQuery script to hide bootstrap fixed navbar on scroll down and reveal on scroll up
/*!
* jQuery script to hide bootstrap fixed navbar on scroll down and reveal on scroll up.
*
* Copyright 2016 James Buncle
*
* Released under the MIT license.
* http://jquery.org/license
*
*/
(function ($) {
$(document).ready(function () {
var $nav = $('.navbar-fixed-top');
var lastScrollTop = 0;
var direction;
$(function () {
$(window).scroll(function () {
var scrollTop = $(this).scrollTop();
if (lastScrollTop < scrollTop && scrollTop > $nav.outerHeight() && direction != 'down') {
//Scroll down
$nav.stop().fadeOut();
direction = 'down';
} else if (lastScrollTop > scrollTop && direction != 'up') {
// Scroll up
$nav.stop().fadeIn();
direction = 'up';
}
lastScrollTop = scrollTop;
});
});
});
}(jQuery));
@marwan
Copy link

marwan commented Jul 20, 2018

Was looking for something like this but many were not working properly. But this one works flawlessly on my computer and iPhone! Thanks a lot! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment