mirror of
https://github.com/codeguy/php-the-right-way.git
synced 2025-08-09 15:36:36 +02:00
Move navhighlight closure to setup.js
Also limits the anchors manipulated to site-navigation
This commit is contained in:
@@ -1,28 +0,0 @@
|
||||
(function ($) {
|
||||
$(window).scroll(function() {
|
||||
//console.log("They see me scrollin, they hatin");
|
||||
|
||||
//clear highlighting
|
||||
$('a').removeClass("active");
|
||||
|
||||
//calc current viewport
|
||||
var viewTop = $(window).scrollTop();
|
||||
var viewBottom = viewTop + $(window).height();
|
||||
|
||||
//for all h1 and h2 elements, check if they are visible
|
||||
//performance tweak: stop each() after the first element is found to be behind view
|
||||
$('h1, h2').each(function(i,e) {
|
||||
//get element position;
|
||||
var eTop = $(e).offset().top;
|
||||
var eBottom = eTop + $(e).height();
|
||||
if (eTop >= viewTop) {
|
||||
if (eBottom <= viewBottom) {
|
||||
$('a[href="#'+e.id+'"]').addClass("active");
|
||||
} else {
|
||||
//console.log("Start skipping test with "+e.id);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
})(jQuery);
|
@@ -24,3 +24,33 @@
|
||||
}).fail(fail);
|
||||
}
|
||||
})(jQuery);
|
||||
|
||||
(function ($) {
|
||||
//Add current view's highlighting to the navigation
|
||||
$(window).scroll(function() {
|
||||
//console.log("They see me scrollin, they hatin");
|
||||
|
||||
//clear highlighting
|
||||
$('.site-navigation a').removeClass("active");
|
||||
|
||||
//calc current viewport
|
||||
var viewTop = $(window).scrollTop();
|
||||
var viewBottom = viewTop + $(window).height();
|
||||
|
||||
//for all h1 and h2 elements, check if they are visible
|
||||
//performance tweak: stop each() after the first element is found to be behind view
|
||||
$('h1, h2').each(function(i,e) {
|
||||
//get element position;
|
||||
var eTop = $(e).offset().top;
|
||||
var eBottom = eTop + $(e).height();
|
||||
if (eTop >= viewTop) {
|
||||
if (eBottom <= viewBottom) {
|
||||
$('.site-navigation a[href="/#'+e.id+'"]').addClass("active");
|
||||
} else {
|
||||
//console.log("Start skipping test with "+e.id);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
})(jQuery);
|
||||
|
Reference in New Issue
Block a user