const hamburgerLink = document.querySelectorAll(
".navlinks .group .sub a"
);
hamburgerLink.forEach((item) => {
item.addEventListener("click", (e) => {
e.preventDefault();
let section = document.querySelector(item.getAttribute("href"));
if (section) {
window.location.hash = `${item.getAttribute("href")}`; // inject hash into url
section.scrollIntoView({
behavior: "smooth",
});
} else {
window.location.replace("/" + item.getAttribute("href")); // just redirect if ever section is not found based on the id
}
toggleNav.click();
});
});
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter