Skip to content

Instantly share code, notes, and snippets.

@mattbrett
Created June 7, 2013 21:02
Show Gist options
  • Save mattbrett/5732402 to your computer and use it in GitHub Desktop.
Save mattbrett/5732402 to your computer and use it in GitHub Desktop.
jQuery: Navigation that sticks to the top once the specified threshold has been passed.
var fixed = false;
jQuery(document).ready(function($) {
$(window).scroll(function() {
if ($(this).scrollTop() >= 100) {
if (!fixed) {
fixed = true;
$('#navigation').css({
position: 'fixed',
top: 0
});
}
} else {
if (fixed) {
fixed = false;
$('#navigation').css({
position: 'absolute',
top: 90
});
}
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment