Difference between revisions of "Template:SJTU-BioX-Shanghai/Navigator"

Line 11: Line 11:
 
   ctt.classList.toggle('nav-toggle')
 
   ctt.classList.toggle('nav-toggle')
 
}
 
}
function toc_loop() {
 
  var TOP = window.pageYOffset + 50;
 
  var headings = $('#toc ~ h2 > span:last-child, #toc ~ h3 >  span:last-child');
 
  if (headings.length == 0) return
 
 
  for (var i = 0; i < headings.length; i++) {
 
    var h = headings[i];
 
    var top = $(h).offset().top;
 
    if (top > TOP ) break
 
  }
 
  if (i > 0) h = headings[i-1]
 
  //set h as reading part
 
  var id = h.id;
 
 
  var prev_a = $('#toc a.reading');
 
  var a = $('a[href="#'+ id +'"]');
 
  prev_a.removeClass('reading');
 
  a.addClass('reading');
 
}
 
function init() {
 
  $('#toc div#toctitle + ul a').click(
 
    function(evnt){
 
      var a = evnt.currentTarget;
 
      var id = a.attributes["href"].value;
 
      var ele = document.getElementById(id.slice(1, id.length));
 
      var top = ele.offsetTop, docEle =  document.documentElement
 
      var pageHeight = docEle.offsetHeight, windowHeight =  docEle.clientHeight
 
 
      if ((pageHeight - top) > windowHeight) setTimeout ("scrollBy(0, -20)", 10);
 
    }
 
  )
 
 
  setInterval("toc_loop()", 10);
 
}
 
 
$(document).ready(init)
 
 
</script>
 
</script>
 
   <nav>
 
   <nav>

Revision as of 06:35, 17 September 2015