Last active
April 25, 2016 15:52
-
-
Save is8r/9a828d251a484b10a6243ea28c912208 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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