{
let currentScrollPos = window.pageYOffset;
if (Math.abs(prevScrollPos - currentScrollPos) > 25) { // Add a threshold to avoid jitter
if (prevScrollPos > currentScrollPos) {
// Scrolling up
$el.style.top = `${topOffset}px`;
} else {
// Scrolling down
$el.style.top = `0px`;
}
prevScrollPos = currentScrollPos;
}
}">