Skip to content

Instantly share code, notes, and snippets.

@benknight
Created November 26, 2013 05:55
Show Gist options
  • Save benknight/7654020 to your computer and use it in GitHub Desktop.
Save benknight/7654020 to your computer and use it in GitHub Desktop.
Improves scrolling perf on Airbnb search page
// Original Logic:
// ---------------
//
// this.initSidebarHeader=function(){
// this.$node.on(
// "scroll",(
// function(){
// var searchResultsPos=this.select("searchResultsSelector").offset();
// if(searchResultsPos.top<=100){
// this.$node.addClass("stuck");
// this.select("textFiltersSelector").show();
// this.select("textMoreFiltersSelector").hide()
// } else {
// this.$node.removeClass("stuck");
// this.select("textMoreFiltersSelector").show();
// this.select("textFiltersSelector").hide()
// }
// }
// ).bind(this)
// )
// };
(function() {
// Cancel current listeners.
$('.sidebar').unbind('scroll');
// Add a more performant listener
$('.sidebar').bind(
'scroll',
function() {
var offset = $('.search-results').offset().top;
var certain_point = 100;
if (offset <= certain_point && ! $(this).is('.stuck')) {
$(this).addClass('stuck');
$('.text-filters').show();
$('.text-more-filters').hide();
} else if (offset > certain_point && $(this).is('.stuck')) {
$(this).removeClass('stuck');
$('.text-filters').hide();
$('.text-more-filters').show();
}
}
);
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment