Skip to content

Instantly share code, notes, and snippets.

@statico
Created September 15, 2011 01:52
Show Gist options
  • Save statico/1218328 to your computer and use it in GitHub Desktop.
Save statico/1218328 to your computer and use it in GitHub Desktop.
airbnb's nifty search scrolling uses onscroll event
var m, j;
var l = jQuery("#search_filters");
var c = jQuery("#search_body");
var p = l.position().top;
var k = l.height();
function n() {
var s = jQuery(window).scrollTop();
var r = l.position().top;
if ((s >= p) && (k < j)) {
if (!l.hasClass("fixed")) {
l.addClass("fixed")
}
if (((k + r) >= m) && s >= r) {
l.css({
position: "absolute",
top: m - k + 1 + "px"
})
} else {
if (l.css("position") === "absolute") {
l.css({
position: "",
top: "0"
})
}
}
} else {
d()
}
}
function d() {
if (l.hasClass("fixed")) {
l.removeClass("fixed")
}
if (l.css("position") === "absolute") {
l.css({
position: "",
top: "0"
})
}
}
function f() {
k = l.height();
n();
n()
}
AirbnbSearch.$.bind("finishedrendering", function () {
p = c.position().top;
k = l.height();
j = c.height();
m = p + j;
if ((j > k) && AirbnbSearch.currentViewType !== "map") {
jQuery(window).scroll(n).scroll();
AirbnbSearch.$.bind("filtertoggle", f)
} else {
jQuery(window).unbind("scroll", n);
AirbnbSearch.$.unbind("filtertoggle", f);
d()
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment