Created
March 9, 2012 02:13
-
-
Save dimitrikennedy/2004620 to your computer and use it in GitHub Desktop.
JavaScript: Sticky Nav
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 $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