Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save cameroncowden/38dfc6f2fb646225e3597c3be25e9750 to your computer and use it in GitHub Desktop.
Save cameroncowden/38dfc6f2fb646225e3597c3be25e9750 to your computer and use it in GitHub Desktop.
(function() {
var banner_height = $('.collection-banner').height() + 220; //220 offset for header
var stuck = false;
var lastScrollY = 0;
var ticking = false;
var filter_dom;
var update = function() {
// do your stuff
if(lastScrollY > banner_height) {
console.log('stickying filters (' + lastScrollY + '>' + banner_height + ')');
// add class for sticky filters
if(!$('#collection-description').hasClass('stuck')) {
$('#collection-description').addClass('stuck');
}
//and move outside content page
if(!stuck) {
var dom = $('#collection-description').detach();
dom.insertAfter('#mobile-only');
dom = null;
}
stuck = true;
} else {
console.log('unsticking filters (' + lastScrollY + '>' + banner_height + ')');
// remove class for sticky filters
if($('#collection-description').hasClass('stuck')) {
$('#collection-description').removeClass('stuck');
}
//move back in to content page
if(stuck) {
var dom = $('#collection-description').detach();
dom.insertAfter('#breadcrumb');
filter_dom = null;
}
stuck = false;
}
ticking = false;
};
var requestTick = function() {
if (!ticking) {
window.requestAnimationFrame(update);
ticking = true;
}
};
var onScroll = function() {
lastScrollY = window.scrollY;
requestTick();
};
$(window).on('scroll', onScroll);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment