-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
20 lines (20 loc) · 787 Bytes
/
Copy pathindex.js
File metadata and controls
20 lines (20 loc) · 787 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
document.addEventListener('DOMContentLoaded', function () {
var sections = document.querySelectorAll('section');
var navLinks = document.querySelectorAll('nav a');
window.addEventListener('scroll', function () {
var current = "";
sections.forEach(function (section) {
var sectionTop = section.offsetTop;
var sectionHeight = section.clientHeight;
if (pageYOffset >= (sectionTop - sectionHeight / 3)) {
current = section.getAttribute('id');
}
});
navLinks.forEach(function (link) {
link.classList.remove('active');
if (link.getAttribute('href').substring(1) === current) {
link.classList.add('active');
}
});
});
});