· 3 min read
A sticky intro, a scroll-spy nav and snapping on the landing
Two columns on the home page from 64rem: the intro (the Hero plus an in-page nav) stays in place on the left while the sections scroll on the right. One…
What we did
- Two columns on the home page from 64rem: the intro (the Hero plus an in-page nav) stays in place on the left while the sections scroll on the right. One column below that.
- New
SectionNav.svelte: an in-page nav that highlights the section being read (a scroll-spy), witharia-current="location", a longer line and the brand color. - A
--header-spacetoken andscroll-padding-block-startonhtml, so the sticky intro and in-page jumps stop below the sticky header. proximityscroll snapping on the sections, only on wide screens and without a reduced-motion preference.- Each section's content is wiped in from the top as it scrolls into view (a
view()timeline animatingclip-path). - Tested on the built site at 1280×800, 1280×700, 320px, both themes and reduced motion.
What I learned
position: stickyinside a grid needsalign-items: start. By default grid items stretch to the row's height, and an element as tall as its container has nowhere to stick.- A sticky element taller than the screen never shows its bottom. So the intro is only sticky on screens at least 45rem tall.
IntersectionObserverwithrootMargin: '-33% 0px -67% 0px'shrinks what it watches to a thin line a third of the way down the screen. Whichever section crosses that line is the current one.- Setting state inside
$effectis usually a smell, but here the value comes from outside Svelte (the observer's callback), so it can't be a$derived. scroll-paddingtells the browser the top of the visible area is lower than it looks. Without it, a jump to#projectsputs the heading under the sticky header.proximitysnaps only when you stop near a snap point;mandatoryalways snaps and fights you on long sections.- A page's CSS stays loaded after you leave it. So the snapping rule is
html:has(.landing), nothtml: it only matches while the landing is on screen. - One animation per element: the sections already run a time-based entrance, so the scroll-driven reveal goes on their
.grid.
Problems & fixes
- The intro was 689px tall: in a narrow 2fr column every link button wrapped onto its own row. Equal columns fixed it (589px).
- The page loaded scrolled down 50px. With proximity snapping, the first section was the nearest snap point on load, so the browser jumped to it. Making the top of the landing a snap point too fixed it.
- I guessed the header at 5rem; it's 98px (about 6.1rem).
--header-spaceis now 6.5rem. - Lighthouse accessibility dropped to 95 on the home page: contrast 1.86:1 on "No projects yet". Lighthouse loads a phone-sized window, where that text is below the fold, so the reveal still had it at
opacity: 0. Switching the reveal from a fade to aclip-pathwipe brought it back to 100 in both themes. /bitacorahad a heading-order warning: the placeholder subtitle was an<h3>right after the<h1>. It's a<p>now.
Links
- MDN: position: sticky
- MDN: Intersection Observer API
- MDN: scroll-snap-type
- MDN: scroll-padding
- MDN: :has()
- brittanychiang.com, the inspiration for the layout
Next
- Real content on the landing, so the layout can be judged (on
feat/content). - View transitions between routes.