var $window = window.$window || $(window),
$document = window.$document || $(document),
$html = window.$html || $('html');
var throttle = function(fn, threshhold, scope) { // throttle
threshhold || (threshhold = 250);
var last,
deferTimer;
return function() {
var context = scope || this;
var now = +new Date,
args = arguments;
if (last && now < last + threshhold) { // hold on to it
clearTimeout(deferTimer);
deferTimer = setTimeout(function() {
last = now;
fn.apply(context, args);
}, threshhold);
} else {
last = now;
fn.apply(context, args);
}
};
};
var scrollTopPrev = -1;
$window.on('scroll', throttle(function(){
var scrollTop = window.pageYOffset || $window.scrollTop();
$html.toggleClass('is-scroll-downed', (scrollTop >= 10));
if (scrollTopPrev !== scrollTop) {
if (scrollTopPrev < scrollTop && scrollTop > 50) { // down, 50 이상 내려갔을 경우
$html.removeClass('is-scroll-up');
$html.addClass('is-scroll-down');
} else if (scrollTopPrev > scrollTop) { // up
$html.addClass('is-scroll-up');
$html.removeClass('is-scroll-down');
}
scrollTopPrev = scrollTop; // cache
}
}, 100));