Skip to content

Instantly share code, notes, and snippets.

@ashaw
Created September 11, 2012 21:16
Show Gist options
  • Save ashaw/3702122 to your computer and use it in GitHub Desktop.
Save ashaw/3702122 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 = 700;
},
stick : function() {
if ($(window).width() < 480) return
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")
.css("top", 0)
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment