Skip to content

Instantly share code, notes, and snippets.

@lenagroeger
Created February 11, 2013 16:15
Show Gist options
  • Save lenagroeger/4755453 to your computer and use it in GitHub Desktop.
Save lenagroeger/4755453 to your computer and use it in GitHub Desktop.
sticky highlight nav bar
propublica.views.getStuck = propublica.View.extend({
tag : "li",
cssClass : "congressperson_box",
render : function() {
_.bindAll(this, "imStuck");
this.jWindow = $(window);
this.jWindow.scroll(this.imStuck);
},
imStuck : function() {
if ($(window).width() < 480) return
var windowTop = this.jWindow.scrollTop();
var sticky = function(index) {
$('#sidebar li').removeClass('active'), $('.' + index + '-bar').addClass('active');
};
this.el.each(function() {
var cur = $(this);
var curTop = cur.offset().top;
var curInx = cur.attr("data-state");
var sidebarTop = $('.'+curInx+'-bar').offset().top;
if (sidebarTop > curTop) {
sticky(curInx);
} else {
}
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment