-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
60 lines (54 loc) · 1.95 KB
/
Copy pathscript.js
File metadata and controls
60 lines (54 loc) · 1.95 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
48
49
50
51
52
53
54
55
56
57
58
59
60
/* ============================================
TYPED.JS — Hero subtitle
============================================ */
document.addEventListener("DOMContentLoaded", () => {
new Typed("#typed-output", {
strings: ["Bug Bounty Hunter.", "Security Researcher."],
typeSpeed: 100,
backSpeed: 30,
backDelay: 1800,
loop: true,
smartBackspace: true,
});
/* ============================================
NAVBAR — highlight active section on scroll
============================================ */
const sections = document.querySelectorAll("section[id]");
const navLinks = document.querySelectorAll(".nav-link");
const mainNav = document.getElementById("mainNav");
const observerOptions = {
root: null,
rootMargin: "-40% 0px -55% 0px",
threshold: 0,
};
const observer = new IntersectionObserver((entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
const id = entry.target.getAttribute("id");
navLinks.forEach((link) => {
link.classList.toggle(
"active-link",
link.getAttribute("href") === `#${id}`,
);
});
}
});
}, observerOptions);
sections.forEach((sec) => observer.observe(sec));
/* ============================================
NAVBAR — add .scrolled class after scroll
============================================ */
window.addEventListener("scroll", () => {
mainNav.classList.toggle("scrolled", window.scrollY > 50);
});
/* ============================================
SMOOTH SCROLL — close mobile nav on link click
============================================ */
navLinks.forEach((link) => {
link.addEventListener("click", () => {
const collapseEl = document.getElementById("navMenu");
const bsCollapse = bootstrap.Collapse.getInstance(collapseEl);
if (bsCollapse) bsCollapse.hide();
});
});
});