Skip to content

Instantly share code, notes, and snippets.

@koentjuh1
Last active August 30, 2016 11:20
Show Gist options
  • Save koentjuh1/ad372b1ec4d5af205f281c948e4d8845 to your computer and use it in GitHub Desktop.
Save koentjuh1/ad372b1ec4d5af205f281c948e4d8845 to your computer and use it in GitHub Desktop.
Set fixed header after scroll top
// Version 1
function adjustHeader1(){
var head = jQuery('.header-bot');
if(jQuery(document).scrollTop() > 50) {
if(!head.hasClass('header-bot-fix')) {
head.addClass('header-bot-fix');
}
}
else {
if(head.hasClass('header-bot-fix')) {
head.removeClass('header-bot-fix');
}
}
}
jQuery(window).on('scroll', function(){
adjustHeader1();
});
// Version 2
$(window).scroll(function() {
var scroll = $(window).scrollTop();
if (scroll > 50) {
$(".header-bot").addClass("header-bot-fix");
}
else {
$(".header-bot").removeClass("header-bot-fix");
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment