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

Line 3: Line 3:
 
<embed src="/wiki/images/d/de/SJTUB_shade.svg" />
 
<embed src="/wiki/images/d/de/SJTUB_shade.svg" />
  
<nav>
+
<script>
 +
function toggle_nav(btn) {
 +
  var ctt = $('#content')[0]
 +
  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>
 +
 
 +
    <nav>
 +
      <div id="hide-nav" onclick="toggle_nav(this)"><svg width="6px" height="24px"><polygon points="6,0 0,12 6,24"/></svg></div>
 +
      <div id="shade"></div>
 
<ul>
 
<ul>
 
   <li><a href="https://2015.igem.org/Team:SJTU-BioX-Shanghai/Gamma">home</a></li>
 
   <li><a href="https://2015.igem.org/Team:SJTU-BioX-Shanghai/Gamma">home</a></li>

Revision as of 04:42, 17 September 2015