forked from fortran-lang/fortran-lang.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
page_nav.js
35 lines (27 loc) · 1018 Bytes
/
page_nav.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// If the current page contains an element with id="page-nav"
// then this script will populate it with <li> elements
// containing links to all the <h2> elements on the current page
if (!!document.getElementById("page-nav")){
var headings = document.querySelectorAll("h2[id]");
for (var i = 0; i < headings.length; i++) {
document.getElementById("page-nav").innerHTML +=
'<li id="nav-' + headings[i].id +
'"><a href="#' + headings[i].id + '">' +
headings[i].innerText +
'</a></li>';
}
$(document).ready(function() {
$(window).scroll(function() {
var found = false;
var scrollPos = $(window).scrollTop();
for (var i = 0; i < headings.length; i++) {
if (scrollPos >= headings[i].offsetTop){
found = true;
$("#nav-"+headings[i].id).addClass('current');
} else {
$("#nav-"+headings[i].id).removeClass('current');
}
}
});
});
}