Guest User

Untitled

a guest
Aug 15th, 2018
315
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. (function() {
  2.  
  3. const section = document.querySelectorAll(".section");
  4. let sections = {};
  5. let i = 0;
  6.  
  7. sectionArray = Array.from(section);
  8. sectionArray.forEach(function(element) {
  9. sections[element.id] = element.offsetTop - 75;
  10. });
  11.  
  12. window.onscroll = function() {
  13. let scrollPosition = document.documentElement.scrollTop || document.body.scrollTop;
  14.  
  15. for (i in sections) {
  16. if (sections[i] <= scrollPosition) {
  17. document.querySelector('.active').setAttribute('class', ' ');
  18. document.querySelector('a[href*=' + i + ']').setAttribute('class', 'active');
  19. }
  20. }
  21. };
  22. })();
Add Comment
Please, Sign In to add comment