Skip to content

Instantly share code, notes, and snippets.

@lenagroeger
Created March 8, 2013 15:22
Show Gist options
  • Save lenagroeger/5117187 to your computer and use it in GitHub Desktop.
Save lenagroeger/5117187 to your computer and use it in GitHub Desktop.
sticky_nav
propublica.views.stickyNav = propublica.View.extend({
cssClass : "sticky_nav",
render : function() {
_.bindAll(this, "stick");
this.jWindow = $(window);
this.jFooter = $("footer");
this.offsetTop = this.el.offset().top;
this.elHeight = this.el.height();
this.jWindow.scroll(this.stick);
this.bottomOffset = 0;
},
stick : function() {
var windowTop = this.jWindow.scrollTop();
var footerTop = this.jFooter.offset().top;
if (windowTop > this.offsetTop && windowTop < footerTop - this.bottomOffset) {
this.el
.css("position", "fixed")
.css("top", 0)
.css("box-shadow", "rgba(0, 0, 0, 0.1) 0px 4px 5px 0px")
$(".congressperson_list").addClass("push_down")
} else if (windowTop > footerTop - this.bottomOffset) {
this.el
.css("position", "absolute")
.css("top", 0)
.css("box-shadow", "rgba(0, 0, 0, 0) 0px 4px 5px 0px")
$(".congressperson_list").removeClass("push_down")
} else {
this.el
.css("position", "relative")
.css("top", 0)
.css("box-shadow", "rgba(0, 0, 0, 0) 0px 4px 5px 0px")
$(".congressperson_list").removeClass("push_down")
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment