Skip to content

Commit

Permalink
Cache navLinks and filter for performance
Browse files Browse the repository at this point in the history
  • Loading branch information
xosofox committed Jul 19, 2012
1 parent 56c0d1c commit a33542b
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions scripts/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
//console.log("They see me scrollin, they hatin");

//clear highlighting
$('.site-navigation a').removeClass("active");
var navLinks=$('.site-navigation a')
navLinks.removeClass("active");

//calc current viewport
var viewTop = $(window).scrollTop();
Expand All @@ -45,7 +46,8 @@
var eBottom = eTop + $(e).height();
if (eTop >= viewTop) {
if (eBottom <= viewBottom) {
$('.site-navigation a[href="/#'+e.id+'"]').addClass("active");
//filter cached navLinks
navLinks.filter('[href="/#'+e.id+'"]').addClass("active");
} else {
//console.log("Start skipping test with "+e.id);
return false;
Expand Down

0 comments on commit a33542b

Please sign in to comment.