Difference between revisions of "Template:SJTU-BioX-Shanghai/Alpha/Header"
Line 5: | Line 5: | ||
var ctt = $('#content')[0] | var ctt = $('#content')[0] | ||
ctt.classList.toggle('nav-toggle') | ctt.classList.toggle('nav-toggle') | ||
+ | } | ||
+ | function toc_loop() { | ||
+ | var TOP = window.pageYOffset; | ||
+ | var headings = $('#toc ~ h2, #toc ~ h3'); | ||
+ | for (var i = 0; i < headings.length; i++) { | ||
+ | var h = headings[i]; | ||
+ | var top = h.offsetTop; | ||
+ | if (top > TOP) break | ||
+ | } | ||
+ | //set h as reading part | ||
+ | var id = h.id; | ||
+ | var prev_a = $('#toc a.reading'); | ||
+ | var a = $('a[herf$="#'+ id +'"]'); | ||
+ | console.log(prev_a, a); | ||
+ | prev_a.removeClass('reading'); | ||
+ | a.addClass('reading'); | ||
} | } | ||
function init() { | function init() { | ||
Line 18: | Line 34: | ||
} | } | ||
) | ) | ||
+ | setInterval("toc_loop()", 1000); | ||
} | } | ||
Revision as of 02:37, 17 August 2015