diff --git a/index.html b/index.html index 60355b6..f60d719 100644 --- a/index.html +++ b/index.html @@ -127,7 +127,7 @@ .controls{display:flex;flex-wrap:wrap;gap:10px;align-items:center;padding-block:8px} /* search + filters + tabs stay at the top while scrolling the list; filters fold away until asked for */ -.stickybar{display:flex;flex-direction:column;gap:14px;position:sticky;top:env(safe-area-inset-top,0px);z-index:5;background:var(--bg);padding-bottom:10px} +.stickybar{display:flex;flex-direction:column;gap:14px;position:sticky;top:env(safe-area-inset-top,0px);z-index:5;background:var(--bg);padding-bottom:10px;box-shadow:0 8px 12px -10px rgba(0,0,0,0);transition:box-shadow .2s ease} #stickSentinel{height:0;margin-bottom:-14px} .stickybar.stuck{gap:6px;padding-bottom:8px;box-shadow:0 8px 12px -10px rgba(0,0,0,.25)} .stickybar.stuck .controls{padding-block:6px 0} @@ -1393,17 +1393,27 @@

Same master fund

const bar = $("#stickyBar"), sen = $("#stickSentinel"), btn = $("#showFilters"); const activeFilters = () => ["#fRegion", "#fType", "#fCat", "#fTax", "#amc"].filter(id => $(id) && $(id).value).length + (st.pick ? 1 : 0); const label = () => { const n = activeFilters(); btn.textContent = (bar.classList.contains("showfilters") ? "Hide filters ▴" : "Filters ▾") + (n ? ` (${n})` : ""); btn.classList.toggle("on", n > 0); }; - const check = () => { - const stuck = sen.getBoundingClientRect().top < -2 && getComputedStyle(bar).position === "sticky"; - if (stuck !== bar.classList.contains("stuck")) { + // The bar is shorter once stuck (filters fold away). Keep the space it takes in the page the + // same with a bottom margin, so the list below never jumps — a jump made scrolling feel jerky + // and could flip the bar back and forth near the switch point. + let fullH = 0; + const keepSpace = () => { bar.style.marginBottom = bar.classList.contains("stuck") ? Math.max(0, fullH - bar.offsetHeight) + "px" : ""; }; + let raf = 0; + const check = () => { if (!raf) raf = requestAnimationFrame(() => { raf = 0; update(); }); }; + const update = () => { + const sticky = getComputedStyle(bar).position === "sticky", top = sen.getBoundingClientRect().top, was = bar.classList.contains("stuck"); + const stuck = sticky && (was ? top < 2 : top < -2); // a little slack so it doesn't flicker at the edge + if (stuck !== was) { + if (stuck) fullH = bar.offsetHeight; bar.classList.toggle("stuck", stuck); if (!stuck) bar.classList.remove("showfilters"); - label(); syncTopScroll(); fhDirty = true; queueFloatHead(); + keepSpace(); label(); syncTopScroll(); fhDirty = true; queueFloatHead(); } }; - btn.onclick = () => { bar.classList.toggle("showfilters"); btn.setAttribute("aria-expanded", bar.classList.contains("showfilters")); label(); syncTopScroll(); queueFloatHead(); }; - window.addEventListener("scroll", check, {passive: true}); window.addEventListener("resize", check); + btn.onclick = () => { bar.classList.toggle("showfilters"); btn.setAttribute("aria-expanded", bar.classList.contains("showfilters")); keepSpace(); label(); syncTopScroll(); queueFloatHead(); }; + window.addEventListener("scroll", check, {passive: true}); + window.addEventListener("resize", () => { if (bar.classList.contains("stuck")) { bar.classList.remove("stuck"); bar.style.marginBottom = ""; } update(); }); bar.addEventListener("change", label); - check(); + update(); } function bindFloatHead(){ const fh = $("#floatHead"), bd = $(".board");