Skip to content

Instantly share code, notes, and snippets.

@jenhuls
Created May 17, 2022 13:20
Show Gist options
  • Save jenhuls/18e2b21be294d693ec7e39ed4141348e to your computer and use it in GitHub Desktop.
Save jenhuls/18e2b21be294d693ec7e39ed4141348e to your computer and use it in GitHub Desktop.
[Add Class to Header on Scroll] #jquery #pinned
(function($) {
$(window).scroll(function() {
var header = $(document).scrollTop();
var headerHeight = $(".header").outerHeight();
if (header > headerHeight) {
$(".header").addClass("fixed");
} else {
$(".header").removeClass("fixed");
}
});
})( jQuery );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment