-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Cory Streiff
committed
Sep 12, 2024
1 parent
b32742f
commit 5dfdf49
Showing
8 changed files
with
160 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const sections = document.querySelectorAll("main > div"); | ||
const navLi = document.querySelectorAll("nav ul li"); | ||
|
||
window.addEventListener("scroll", () => { | ||
let current = ""; | ||
sections.forEach((section) => { | ||
const sectionTop = section.offsetTop; | ||
const sectionHeight = section.clientHeight; | ||
if (pageYOffset >= sectionTop - 200 - Math.sqrt(sectionHeight)) { | ||
current = section.getAttribute("id"); | ||
} | ||
}); | ||
|
||
navLi.forEach((li) => { | ||
li.classList.remove("active"); | ||
if (li.classList.contains(current)) { | ||
li.classList.add("active"); | ||
} | ||
}); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.