File size: 689 Bytes
4d6f2bc
6278196
4d6f2bc
 
e667f80
4d6f2bc
e667f80
 
 
 
 
4d6f2bc
e667f80
 
 
 
 
 
 
 
4d6f2bc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
() =>{
  const header = document.querySelector("#intro");
  const menu = document.querySelector("#menu");
  const menuButton = menu.querySelector("button");
  const menuSpan = menuButton.querySelector("span:first-child");

  const updateMenuText = () => {
    const isOpen = menuButton.classList.contains("open");
    menuSpan.textContent = isOpen ? "Close menu" : "Open menu";

    if (isOpen) {
      menu.scrollIntoView({ behavior: "instant" });
    } else {
      header.scrollIntoView({ behavior: "instant" });
    }
  };

  const observer = new MutationObserver(updateMenuText);
  observer.observe(menuButton, { attributes: true, attributeFilter: ["class"] });
  updateMenuText();
}