diff --git a/tools/test_site_browser.cjs b/tools/test_site_browser.cjs index 7d54890..3301aa9 100644 --- a/tools/test_site_browser.cjs +++ b/tools/test_site_browser.cjs @@ -82,14 +82,25 @@ pages.unshift(''); await page.click('.menu'); if (!(await page.isVisible('#site-nav'))) failures.push(`${width}: mobile menu does not open`); if (shots) await page.screenshot({ path: path.join(shots, `site-${width}-menu.png`) }); - // The bar stays on top while scrolling; the open menu fits the screen - // and closes on page scroll, a tap outside or Escape. + // The open menu fits the screen and closes on page scroll, a tap + // outside or Escape. The bar slides away while scrolling down (it never + // covers the text being read) and comes back on scroll up and at the top. const fits = await page.evaluate(() => document.getElementById('site-nav').getBoundingClientRect().bottom <= innerHeight + 1); if (!fits) failures.push(`${width}: open menu taller than the screen`); - await page.evaluate(() => scrollTo(0, 600)); await page.waitForTimeout(250); + const barTop = () => page.evaluate(() => Math.round(document.querySelector('.top').getBoundingClientRect().bottom)); + await page.evaluate(() => scrollTo(0, 600)); await page.waitForTimeout(400); if (await page.isVisible('#site-nav')) failures.push(`${width}: menu stays open while the page scrolls`); + await page.evaluate(() => scrollTo(0, 900)); await page.waitForTimeout(400); + if (await barTop() > 1) failures.push(`${width}: header covers the text while scrolling down`); + await page.evaluate(() => scrollTo(0, 700)); await page.waitForTimeout(400); if (await page.evaluate(() => Math.round(document.querySelector('.top').getBoundingClientRect().top)) !== 0) - failures.push(`${width}: header does not follow the scroll`); + failures.push(`${width}: header does not come back on scroll up`); + await page.evaluate(() => scrollTo(0, 1100)); await page.waitForTimeout(400); + await page.evaluate(() => scrollTo(0, 0)); await page.waitForTimeout(400); + if (await page.evaluate(() => Math.round(document.querySelector('.top').getBoundingClientRect().top)) !== 0) + failures.push(`${width}: header hidden at the top of the page`); + await page.evaluate(() => scrollTo(0, 400)); await page.waitForTimeout(400); + await page.evaluate(() => scrollTo(0, 300)); await page.waitForTimeout(400); await page.click('.menu'); await page.click('main h2, main p'); if (await page.isVisible('#site-nav')) failures.push(`${width}: menu stays open after a tap outside`); await page.click('.menu'); await page.keyboard.press('Escape'); diff --git a/website/assets/site.css b/website/assets/site.css index bdc397f..93194f3 100644 --- a/website/assets/site.css +++ b/website/assets/site.css @@ -201,7 +201,9 @@ summary { cursor: pointer; font-weight: 600; } * menu never grows past the screen: it scrolls inside, and site.js closes * it when the page scrolls, on a tap outside or with Escape, so it cannot * stay over the page heading. Anchored headings stop below the bar. */ - .top { backdrop-filter: none; background: var(--bg); } + .top { backdrop-filter: none; background: var(--bg); transition: transform .2s ease; } + /* site.js hides the bar while scrolling down and shows it on scroll up. */ + .top.is-hidden { transform: translateY(-100%); } .site-nav.open { max-height: calc(100vh - 80px); max-height: calc(100dvh - 80px); overflow-y: auto; overscroll-behavior: contain; } main [id] { scroll-margin-top: 80px; } .tools .menu { display: inline-flex; } @@ -239,6 +241,7 @@ summary { cursor: pointer; font-weight: 600; } @media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; transition: none !important; } } .release-note { margin: 0 0 2rem; padding: 1rem 1.2rem; border: 1px solid var(--line); border-left: 3px solid #1FC97A; border-radius: 12px; font-size: .94rem; line-height: 1.65; } .release-note strong { display: block; margin-bottom: .3rem; } +@media (prefers-reduced-motion: reduce) { .top { transition: none; } } @media print { .top, .sidebar, .foot, .copy { display: none; } } /* Interactive hardware diagram (07-hardware, generated by tools/make_hardware_diagram.py). */ svg.hw { display: block; width: 100%; height: auto; font-family: var(--font); } diff --git a/website/assets/site.js b/website/assets/site.js index 3dcd46b..898eda7 100644 --- a/website/assets/site.js +++ b/website/assets/site.js @@ -76,6 +76,26 @@ }); } + // Phones: the bar slides away while scrolling down and comes back on any + // scroll up, so it never sits over the text being read; it stays visible + // near the top of the page, while the menu is open and on keyboard focus. + var bar = document.querySelector('.top'); + if (bar && window.matchMedia) { + var phone = window.matchMedia('(max-width: 760px)'); + var lastY = window.scrollY; + var showBar = function () { bar.classList.remove('is-hidden'); }; + var updateBar = function () { + var y = window.scrollY, nearTop = y <= bar.offsetHeight; + if (!phone.matches || nearTop || (nav && nav.classList.contains('open'))) showBar(); + else if (y > lastY + 8) bar.classList.add('is-hidden'); + else if (y < lastY - 8) showBar(); + if (nearTop || Math.abs(y - lastY) > 8) lastY = y; + }; + window.addEventListener('scroll', updateBar, { passive: true }); + bar.addEventListener('focusin', showBar); + if (phone.addEventListener) phone.addEventListener('change', showBar); + } + var theme = document.querySelector('.theme'); if (theme) theme.addEventListener('click', function () { var current = doc.getAttribute('data-theme') ||