Last active
August 29, 2015 14:28
-
-
Save vctrfrnndz/66013899c31e578ac0f9 to your computer and use it in GitHub Desktop.
Sticky
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
$(window) | |
.on('scroll', onScroll); | |
function onScroll() { | |
var sticky = $('.js-sticky-nav').filter(':visible'); | |
if (sticky.length) { | |
toggleSticky(sticky); | |
} | |
} | |
function toggleSticky($nav) { | |
if (!$nav.hasClass('is-fixed')) { | |
navOffset = $nav.offset().top; | |
} | |
var isFixed = $(window).scrollTop() > navOffset; | |
$nav.toggleClass('is-fixed', isFixed); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment