Scroll direction, :target-before and rounded polygon()

I wanted to see how three newer CSS features behave when they drive a 2D drawable canvas. Scroll the article below to fold its toolbar with @container scroll-state(scrolled) and zero scroll listeners, swipe the carousel to fan cards from :target-before and :target-after, then drag the clipped card to tilt a polygon(round ...) silhouette and its shadow.

01 · scroll-state

Scroll down to fold the toolbar

This scroller carries container-type: scroll-state. Scrolling down sets scrolled: bottom and transitions --hide to 1.

02 · live controls

The search box filters these notes

Type a word like "shadow" or "fan" into the toolbar above when it is open. The DOM inside the canvas filters these cards in place.

03 · zero scroll listeners

No scroll handler is attached here

Scrolling this drawable child changes its picture and fires the canvas paint event. The script reads --hide and folds the toolbar in two hinged halves.

04 · registered property

@property --hide interpolates cleanly

Because --hide is registered as a number, Chrome transitions it smoothly between 0 and 1 so the canvas draws the intermediate fold angles.

05 · scroll back up

Reverse direction to unfold it

Flick back towards the top and @container scroll-state(scrolled: top) returns --hide to 0. Once flat, the toolbar takes taps and typing again.

06 · focus safety

Hidden toolbars turn inert

When the toolbar is folded past 60%, the script marks it inert so keyboard Tab navigation skips controls you cannot see.

07 · fallback controls

Works with manual toggles too

If your browser does not parse scroll-state(scrolled) yet, use the Simulate buttons below the canvas to drive the same --hide transition.

Show the code scroll-state(scrolled) → --hide → 2D accordion fold
  1. Register --hide and toggle it from @container scroll-state(scrolled). No scroll listener is needed.
  2. Put the scroller and toolbar inside one 2D canvas. Both carry drawable.
  3. Read --hide on paint and fold the toolbar into two shaded halves. Every drawElementImage() call passes explicit width and height.

:target-before and :target-after carousel fan

This horizontal list uses scroll-snap-type, ::scroll-marker and ::scroll-button(). The CSS rules for :target-before, :target-current and :target-after style the dots and set --fan-side and --fan-tilt on each marker. The 2D canvas reads those properties to tilt passed cards left, centre the active card and stack upcoming cards on the right. Every card holds a live Pin button and Lock checkbox.

  • 01

    Ember

    Swipe left or press the arrow buttons. Passed cards tilt into the left stack.

  • 02

    Ochre

    The green dots to the left match :target-before in CSS.

  • 03

    Moss

    The wide orange pill matches :target-current and pulls this card forward.

  • 04

    Slate

    The blue dots to the right match :target-after and queue cards on the right.

  • 05

    Indigo

    Each card sits outside the scroller clip so its drawn picture stays whole.

  • 06

    Plum

    Tap Pin or tick Lock on the centred card to verify live hit testing.

Green dots: :target-before · Orange pill: :target-current · Blue dots: :target-after

Show the code ::scroll-marker:target-before / :target-after → canvas fan
  1. Style markers and set --fan-side and --fan-tilt from :target-before, :target-current and :target-after.
  2. Nested drawable cards inside a drawable deck. Each card is uploaded without scroller clipping.
  3. Read each marker's computed custom properties and fan the cards back to front.

Rounded polygon(round ...) clip paths on drawn cards

Switch between four clip shapes and move the corner-radius slider, then drag across the card to tilt it. Because drawElementImage() preserves transparent pixels outside the card's CSS clip-path, the 2D canvas shadow follows the notched or rounded outline rather than a rectangle.

HEXAGON · GATE 14

LON to TYO

Drag to tilt the clipped card. Tap the controls inside it.

Show the code clip-path: polygon(round ...) → tilt and matching shadow
  1. Apply clip-path: polygon(round ...) with a sharp polygon() fallback.
  2. One live interactive card inside the 2D canvas.
  3. Tilt the canvas context from pointer coordinates and cast a drop shadow from the clipped silhouette.

How it works

Live checks

Each check builds its own isolated fixture on the test stage and reads pixels from a plain 2D copy canvas. Nothing touches the three demos above.

ResultExperimentDetail

Findings

Browser support for scroll-state(scrolled), :target-before/:target-after and polygon(round ...) varies across Chrome 130 to 160. The live checks table above reports what your browser does right now.