Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function() {
- const section = document.querySelectorAll(".section");
- let sections = {};
- let i = 0;
- sectionArray = Array.from(section);
- sectionArray.forEach(function(element) {
- sections[element.id] = element.offsetTop - 75;
- });
- window.onscroll = function() {
- let scrollPosition = document.documentElement.scrollTop || document.body.scrollTop;
- for (i in sections) {
- if (sections[i] <= scrollPosition) {
- document.querySelector('.active').setAttribute('class', ' ');
- document.querySelector('a[href*=' + i + ']').setAttribute('class', 'active');
- }
- }
- };
- })();
Add Comment
Please, Sign In to add comment