Skip to content

Instantly share code, notes, and snippets.

@lenagroeger
Created November 10, 2014 18:25
Show Gist options
  • Save lenagroeger/4675a61c868b324a03ff to your computer and use it in GitHub Desktop.
Save lenagroeger/4675a61c868b324a03ff to your computer and use it in GitHub Desktop.
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 = 250;
},
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", 5);
} else if (windowTop > footerTop - this.bottomOffset) {
this.el
.css("position", "absolute")
.css("top", footerTop - this.bottomOffset);
} else {
this.el
.css("position", "relative");
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment