Last active
August 30, 2016 11:20
-
-
Save koentjuh1/ad372b1ec4d5af205f281c948e4d8845 to your computer and use it in GitHub Desktop.
Set fixed header after scroll top
This file contains 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
// 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