Created
May 5, 2013 16:42
-
-
Save NathanQ/5521345 to your computer and use it in GitHub Desktop.
jQuery stick to the top of the page header
This file contains 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 schtickm = $("header"), pos = schtickm.offset(); | |
$(window).scroll(function() { | |
if($(this).scrollTop() > (pos.top + 10) && | |
schtickm.css('position') == 'static') { schtickm.addClass('fixed'); } | |
else if($(this).scrollTop() <= pos.top && | |
schtickm.hasClass('fixed')){ schtickm.removeClass('fixed'); } | |
}) | |
}); |
.fixed{
position: fixed;
top:0;
bottom:0;
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This assumes the css of the header has a position rule of static.