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.
Show the code scroll-state(scrolled) → --hide → 2D accordion fold
- Register
--hideand toggle it from@container scroll-state(scrolled). No scroll listener is needed. - Put the scroller and toolbar inside one 2D canvas. Both carry
drawable. - Read
--hideonpaintand fold the toolbar into two shaded halves. EverydrawElementImage()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.
:target-before · Orange pill: :target-current · Blue dots: :target-after
Show the code ::scroll-marker:target-before / :target-after → canvas fan
- Style markers and set
--fan-sideand--fan-tiltfrom:target-before,:target-currentand:target-after. - Nested drawable cards inside a drawable deck. Each card is uploaded without scroller clipping.
- 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.
Show the code clip-path: polygon(round ...) → tilt and matching shadow
- Apply
clip-path: polygon(round ...)with a sharppolygon()fallback. - One live interactive card inside the 2D canvas.
- Tilt the canvas context from pointer coordinates and cast a drop shadow from the clipped silhouette.
How it works
- In the first demo,
#s1-scrollercarriescontainer-type: scroll-stateand is adrawablechild of the canvas. When you scroll it, its painted pixels change and Chrome fires the canvaspaintevent without anyscrolllistener. A probe inside the scroller matches@container scroll-state(scrolled: bottom)ortopand transitions--hide. Thepainthandler reads--hideviagetComputedStyle()and draws#s1-toolbareither flat (for exact hit testing when open) or split across two clipped, shaded accordion panels. - In the second demo,
#f2-deckis adrawablechild that holds the horizontal snap list, generated::scroll-button()arrows and::scroll-markerdots. Each card is a nesteddrawablechild positioned against the deck so the scroller never clips its picture. On every paint, the script reads--fan-sideand--fan-tiltfromgetComputedStyle(stop, '::scroll-marker')and draws the passed cards tilted left, the upcoming cards stacked right and the current card last on top. - In the third demo, the card's CSS
clip-pathpunches transparent pixels outside the polygon in the element picture. Canvas 2D shadows (shadowColor,shadowBlur,shadowOffsetX,shadowOffsetY) trace the non-transparent alpha ofdrawElementImage(), so the shadow automatically follows notches, chevrons and rounded corners. When a browser doesn't parsepolygon(round ...)yet, the canvas builds a matchingarcTo()path for the shadow and clip so the radius slider stays usable.
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.
| Result | Experiment | Detail |
|---|
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.
- Scroll direction without scroll listeners: scrolling a drawable 2D child updates its picture and raises
painton the canvas. Pairing that with@container scroll-state(scrolled: bottom)and a registered@property --hidelets the canvas fold a live toolbar without touching thescrollevent. - Hit testing during a split draw: when a drawable element is drawn in two clipped halves to fake an accordion crease, the second
drawElementImage()call overwrites the hit box. Drawing the toolbar in one call once--hide <= 0.01restores exact hit boxes, and marking itinertpast 60% folded keeps hidden inputs out of Tab order. - Reading custom properties from
::scroll-marker:getComputedStyle(slide, '::scroll-marker').getPropertyValue('--fan-side')lets the canvas inspect:target-before,:target-currentand:target-afterdirectly in CSS. When a browser lacks those pseudo-classes, falling back toscrollLeftkeeps the fan working. - Clipped alpha and canvas shadows:
clip-path: polygon(...)is baked into the element's picture beforedrawElementImage()receives it, so 2D drop shadows follow the clipped polygon outline. - Not verified here: real touch fling behaviour, Chrome 159 on Android and exact Chrome milestone rollout for
polygon(round ...)in a headless run. Seefindings/scroll-directions.mdfor the full record.