Skip to content

Instantly share code, notes, and snippets.

@Kcko
Created April 5, 2016 11:39
Show Gist options
  • Select an option

  • Save Kcko/5176ea826e166cccb80228f7132436a2 to your computer and use it in GitHub Desktop.

Select an option

Save Kcko/5176ea826e166cccb80228f7132436a2 to your computer and use it in GitHub Desktop.
Stay on top
$(function(){
var $win = $(window)
var $nav = $('.mytoolbar');
var navTop = $('.mytoolbar').length && $('.mytoolbar').offset().top;
var isFixed=0;
processScroll()
$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