Created
November 19, 2012 14:33
-
-
Save coolniikou/4110951 to your computer and use it in GitHub Desktop.
affix
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
// fix sub nav on scroll | |
var $win = $(window) | |
, $nav = $('.subnav') | |
, navTop = $('.subnav').length && $('.subnav').offset().top - 40 | |
, isFixed = 0 | |
processScroll() | |
$nav.on('click', | |
function () { | |
if (!isFixed) setTimeout(function () { $win.scrollTop($win.scrollTop() - 47) }, 10) | |
}) | |
$win.on('scroll', processScroll) | |
function processScroll() { | |
var i, scrollTop = $win.scrollTop() | |
if (scrollTop >= navTop && !isFixed) { | |
isFixed = 1 | |
$nav.addClass('subnav-fixed') | |
} else if (scrollTop <= navTop && isFixed) { | |
isFixed = 0 | |
$nav.removeClass('subnav-fixed') | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment