Link to other page
Fri Oct 07 2022 05:15:12 GMT+0000 (Coordinated Universal Time)
Saved by
@25vitalyzd2
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();
});
});
content_copyCOPY
Comments