Created
July 23, 2012 23:02
-
-
Save BlakeWilliams/3166796 to your computer and use it in GitHub Desktop.
Scroll Style
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
| var $win = $(window) | |
| , $nav = $('.subnav') | |
| , navTop = $('.subnav').length && $('.subnav').offset().top - 40 | |
| , isFixed = 0 | |
| processScroll() | |
| // hack sad times - holdover until rewrite for 2.1 | |
| $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