Created
December 9, 2016 11:09
-
-
Save artygrand/8f0ea2570b20c7d80dace2bc73dfcb92 to your computer and use it in GitHub Desktop.
Fixed nav on scroll
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
var nav_offset = $('nav').offset().top, | |
nav_height = $('nav').outerHeight(true); | |
$('nav').after($('<div>').addClass('padding').css('height', nav_height)); | |
$(window).scroll(function(){ | |
if ($(this).scrollTop() > nav_offset){ | |
$('nav').addClass('fixed') | |
} else { | |
$('nav').removeClass('fixed') | |
} | |
}); |
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
nav.fixed {position: fixed;top: 0;width: 100%;z-index: 1000;} | |
nav+.padding {display: none;} | |
nav.fixed+.padding {display: block;} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment