diff --git a/index.html b/index.html index d3bbc51..f8bc2e7 100644 --- a/index.html +++ b/index.html @@ -266,8 +266,16 @@ var nr = nav.getBoundingClientRect(); nav.classList.toggle('on-dark', darkBehind((nr.top + nr.bottom) / 2)); if (menu && menu.classList.contains('open')) { - var mr = menu.getBoundingClientRect(); - menu.classList.toggle('on-dark', darkBehind((mr.top + mr.bottom) / 2)); + // Flip the menu when the dark boundary reaches its TEXT — the lowest link's + // leading edge — not the panel's midpoint. The links are top-anchored, so the + // midpoint sits well below them: by the time dark reached it, the text had + // already been over dark. Probing the lowest link makes the switch land as the + // boundary enters the text, just like the (thin) nav bar flips at its content. + var links = menu.querySelectorAll('a'); + var probe = links.length + ? links[links.length - 1].getBoundingClientRect().bottom + : (function () { var mr = menu.getBoundingClientRect(); return (mr.top + mr.bottom) / 2; })(); + menu.classList.toggle('on-dark', darkBehind(probe)); } } updateNavTheme();