Skip to content

Instantly share code, notes, and snippets.

@zhuochun
Created December 6, 2012 03:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zhuochun/4221601 to your computer and use it in GitHub Desktop.
Save zhuochun/4221601 to your computer and use it in GitHub Desktop.
Scroll Fix on Top Navbar
// fix navbar on scroll
var $win = $(window)
, $nav = $('.navbar')
, navTop = $('.navbar').length && $('.navbar').offset().top - 10
, isFixed = 0
processScroll()
$win.on('scroll', processScroll)
function processScroll() {
var i, scrollTop = $win.scrollTop()
if (scrollTop >= navTop && !isFixed) {
isFixed = 1
$nav.addClass('navbar-fixed-top')
} else if (scrollTop <= navTop && isFixed) {
isFixed = 0
$nav.removeClass('navbar-fixed-top')
}
}
$('.page-navigator li:not(:has(a))').html('<a>...</a>');
$('.page-navigator .current').addClass('active');
$('.entry-content a').attr('target','_blank');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment