-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjs.js
More file actions
47 lines (38 loc) · 1.22 KB
/
js.js
File metadata and controls
47 lines (38 loc) · 1.22 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
38
39
40
41
42
43
44
45
46
47
let section = document.querySelectorAll("section");
let menu = document.querySelectorAll("header nav a");
window.onscroll = () => {
section.forEach((i) => {
let top = window.scrollY;
let offset = i.offsetTop - 150;
let height = i.offsetHeight;
let id = i.getAttribute("id");
if (top >= offset && top < offset + height) {
menu.forEach((link) => {
link.classList.remove("active");
document
.querySelector("header nav a[href*=" + id + "]")
.classList.add("active");
});
}
});
};
function reveal() {
var reveals = document.querySelectorAll(".reveal");
for (var i = 0; i < reveals.length; i++) {
var windowHeight = window.innerHeight;
var elementTop = reveals[i].getBoundingClientRect().top;
var elementVisible = 150;
if (elementTop < windowHeight - elementVisible) {
reveals[i].classList.add("active");
} else {
reveals[i].classList.remove("active");
}
}
}
window.addEventListener("scroll", reveal);
// To check the scroll position on page load
reveal();
$('a[href]').each(function() {
if ($(this).attr('href') == window.location.pathname || $(this).attr('href') == window.location.href)
$(this).addClass('active');
});