Prevent JS errors when scrolling on pages that aren’t the main page
This commit is contained in:
parent
e96efcd675
commit
7a9b57c56e
|
@ -33,7 +33,10 @@ document.addEventListener("DOMContentLoaded", () => {
|
|||
const observer = new IntersectionObserver(entries => {
|
||||
entries.forEach(entry => {
|
||||
const id = entry.target.previousElementSibling.id;
|
||||
const menuListItem = document.querySelector(`nav li a[href="/#${id}"]`).parentElement;
|
||||
const menuListItem = document.querySelector(`nav li a[href="/#${id}"]`)?.parentElement;
|
||||
|
||||
if (menuListItem == null)
|
||||
return;
|
||||
|
||||
if (entry.intersectionRatio > 0) {
|
||||
menuListItem.classList.add("active");
|
||||
|
|
Loading…
Reference in a new issue