Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save DevShahidul/b9fda8416f599c9dfad9ad2816d85bbf to your computer and use it in GitHub Desktop.

Select an option

Save DevShahidul/b9fda8416f599c9dfad9ad2816d85bbf to your computer and use it in GitHub Desktop.
if ($(window).width() > 767) {
lasPos = 0
var getHeaderHeight = $('.header-section').outerHeight();
$(window).scroll(function () {
var wScroll = $(window).scrollTop();
$('.header-section').css('top', '-' + getHeaderHeight + 'px')
if (wScroll > 250) {
$('.header-section').addClass('is-active').css('top', 0);
if (lasPos > wScroll) {
$('.header-section').css('top', 0);
} else {
$('.header-section').css('top', '-' + getHeaderHeight-5 + 'px');
}
lasPos = wScroll
} else {
$('.header-section').removeClass('is-active').css('top', '-' + getHeaderHeight + 'px');
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment