Skip to content

Instantly share code, notes, and snippets.

@dimitrikennedy
Created March 9, 2012 02:13
Show Gist options
  • Save dimitrikennedy/2004620 to your computer and use it in GitHub Desktop.
Save dimitrikennedy/2004620 to your computer and use it in GitHub Desktop.
JavaScript: Sticky Nav
$(function () {
var $el = $(''),
originalTop = $el.offset().top;
function sticky(){
if ($(this).scrollTop() > originalTop && $(window).width() > 1024){
$el.css({'position': 'fixed', 'top': '20px'});
} else {
$el.css({'position': 'absolute', 'top': '0px' });
}
}
$(window).on('resize scroll', sticky).trigger('scroll');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment