Skip to content

Instantly share code, notes, and snippets.

@is8r
Last active April 25, 2016 15:52
Show Gist options
  • Save is8r/9a828d251a484b10a6243ea28c912208 to your computer and use it in GitHub Desktop.
Save is8r/9a828d251a484b10a6243ea28c912208 to your computer and use it in GitHub Desktop.
var element = '.js-followheader';
var lastY = 0;
var minY = $(element).height();
$(window).on('scroll', _.throttle(updateScroll, 100));
function updateScroll(e) {
var y = $(window).scrollTop();
if (y < lastY) {
plugin.scrollUp(y);
} else if (y > lastY) {
plugin.scrollDown(y);
}
lastY = $(window).scrollTop();
}
function scrollUp(y) {
$(element).removeClass('is-close');
if (y > minY) {
if(!$(element).hasClass('is-open')) {
$(element).addClass('is-open');
}
} else if(y <= 0){
$(element).removeClass('is-open');
}
}
function scrollDown(y) {
if (y > minY) {
if($(element).hasClass('is-open')) {
$(element).removeClass('is-open');
$(element).addClass('is-close');
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment