-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
37 lines (36 loc) · 1.01 KB
/
Copy pathscript.js
File metadata and controls
37 lines (36 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Smooth scroll
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault(); document.querySelector(this.getAttribute('href')).scrollIntoView({
behavior: 'smooth'
});
});
});
document.addEventListener("DOMContentLoaded", () => {
(function scrollSpy() {
const targets = document.querySelectorAll(".section"),
options = {
threshold: 0.35
};
// If IntersectionObserver is supported
if ("IntersectionObserver" in window) {
(() => {
const inView = target => {
const interSecObs = new IntersectionObserver(entries => {
entries.forEach(entry => {
const elem = entry.target;
let currentNav = document.querySelector(
`#nav a[href='#${elem.id}']`
);
entry.isIntersecting
? currentNav.classList.add("active")
: currentNav.classList.remove("active");
});
}, options);
interSecObs.observe(target);
};
targets.forEach(inView);
})();
}
})();
});