Created
November 26, 2013 05:55
-
-
Save benknight/7654020 to your computer and use it in GitHub Desktop.
Improves scrolling perf on Airbnb search page
This file contains 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
// 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