Created
November 19, 2019 20:01
-
-
Save debonx/e3d5e76a35cc410be3d119f1b797fb04 to your computer and use it in GitHub Desktop.
Sticky navigation bar in jQuery.
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(){ | |
var position; | |
var width = $(window).width(); | |
var position = $(this).scrollTop(); | |
$(document).scroll(function() { | |
var currentScroll = $(this).scrollTop(); | |
//Detecting if it's scrolling down | |
if( currentScroll > position ){ | |
//Instructions for breakpoints after certain amount of pixels | |
if (currentScroll > 400) { | |
$('#top-bar').slideUp(0); | |
} | |
//Detecting if it's scrolling up | |
} else { | |
//Specify other actions after scrolling up | |
if(!$('#top-bar').is(':visible')){ | |
$('#top-bar').slideDown(150).delay(1000); | |
} | |
} | |
position = currentScroll; | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment