Difference between revisions of "Template:TU Darmstadt/JS"

Line 26: Line 26:
 
   var as = document.getElementById('toc').getElementsByTagName('a');
 
   var as = document.getElementById('toc').getElementsByTagName('a');
 
   document.addEventListener('scroll', function () {
 
   document.addEventListener('scroll', function () {
 +
    var activeA = null;
 
     for (var a of as) {
 
     for (var a of as) {
 +
      a.classList.remove('active');
 +
 
       var id = a.href.replace(/.+?#/, '');
 
       var id = a.href.replace(/.+?#/, '');
 
       var element = document.getElementById(id);
 
       var element = document.getElementById(id);
Line 37: Line 40:
 
       var active = y < 50;
 
       var active = y < 50;
 
       if (active) {
 
       if (active) {
          console.log(id);
+
        activeA = a;
 
       }
 
       }
 
     }
 
     }
 +
 +
    activeA.classList.add('active');
 
   });
 
   });
 
    
 
    

Revision as of 15:46, 6 October 2018