index: no longer using snippets
[bootswatch] / js / application.js
1 !function ($) {
2
3   $(function(){
4
5     // fix sub nav on scroll
6     var $win = $(window)
7       , $nav = $('.subnav')
8           , navHeight = $('.navbar').first().height()
9       , navTop = $('.subnav').length && $('.subnav').offset().top - navHeight
10       , isFixed = 0
11
12     processScroll()
13
14     $win.on('scroll', processScroll)
15
16     function processScroll() {
17       var i, scrollTop = $win.scrollTop()
18       if (scrollTop >= navTop && !isFixed) {
19         isFixed = 1
20         $nav.addClass('subnav-fixed')
21       } else if (scrollTop <= navTop && isFixed) {
22         isFixed = 0
23         $nav.removeClass('subnav-fixed')
24       }
25     }
26
27   })
28
29 }(window.jQuery)