The Navbar Sliding Pill creates an animated highlight that slides under navigation links as the user hovers over them.
You can edit the code by going into any Page Settings → Before </body> tag
function initNavbarPill() {
const navLinks = document.querySelectorAll(".navbar---link");
const container = document.querySelector(".navbar---links");
if (!navLinks.length || !container) return;
const pill = container.querySelector(".navbar---pill");
if (!pill) return;
let isVisible = false;
gsap.set(pill, { autoAlpha: 0 });
const slideX = gsap.quickTo(pill, "x", { duration: 0.2, ease: "power3.out" });
const slideWidth = gsap.quickTo(pill, "width", { duration: 0.1, ease: "power3.out" });
navLinks.forEach((link) => {
link.addEventListener("mouseenter", () => {
if (!isVisible) {
gsap.set(pill, { x: link.offsetLeft, width: link.offsetWidth });
gsap.to(pill, { autoAlpha: 1, duration: 0.15, ease: "power2.out" });
isVisible = true;
} else {
slideX(link.offsetLeft);
slideWidth(link.offsetWidth);
}
});
});
container.addEventListener("mouseleave", () => {
gsap.to(pill, {
autoAlpha: 0,
duration: 0.15,
ease: "power2.in",
onComplete: () => { isVisible = false; }
});
});
}
initNavbarPill();
You can modify the values below to adjust the slide speed and easing of the pill.
// Controls how fast the pill slides horizontally to the next link
const slideX = gsap.quickTo(pill, "x", { duration: 0.2, ease: "power3.out" });
// Controls how fast the pill resizes to match the link width
const slideWidth = gsap.quickTo(pill, "width", { duration: 0.1, ease: "power3.out" });
// Controls how fast the pill fades in on hover
gsap.to(pill, { autoAlpha: 1, duration: 0.15, ease: "power2.out" });
// Controls how fast the pill fades out when the mouse leaves
gsap.to(pill, { autoAlpha: 0, duration: 0.15, ease: "power2.in" });
To temporarily disable the code, comment out the whole block like this.
<!--
function initNavbarPill() {
...
}
initNavbarPill();
-->