Originally published at grzegorzotto.dev. Translated from Polish with AI; the Polish original is my own writing.
A page effect does not have to cost you SEO or accessibility: move the real elements with a transform instead of painting a screenshot of them.
On grzegorzotto.dev, on the home page / and on the /projects page, there is a Collapse button (on a phone, an icon in the top bar). Click it and the page collapses: headings, cards and the table fall, collide and pile up at the bottom of the screen. None of it is an image. These are the same DOM nodes that were there before the click, only moved and rotated by CSS transform.
This post is about why I built it this way, what broke on the way, and what I built and then threw away.
Why a transform and not a screenshot into a canvas
The obvious alternative is to take a snapshot of the page into a canvas and "smash" the picture. It looks the same and avoids the trouble of a real page layout. I rejected it from the start: a snapshot hides the real text and is worse for SEO.
Moving the real elements leaves the content in the HTML. A search engine sees the same content, and once the effect is closed, screen readers and text selection work as before, because no element ever disappeared. The effect keeps three rules: page elements are never removed or turned into an image, the physics code loads through import() only on the first click, and the system's reduced-motion setting (prefers-reduced-motion) is always respected. You can check each one yourself in your browser's developer tools: in the element tree, in the network tab and by simulating that setting (in Chrome: the Rendering tab).
Effect first, engine second, against the plan
I wanted the portfolio itself to show what my 2D engine can do. The plan said something different from what I did. On 2026-06-30 I wrote the decision down plainly: full hold, do not hand-roll this in the portfolio, engine first, the page effect as the engine's first test on a real project of my own (dogfooding).
I broke that hold less than a day later. I wanted to see it work on the real DOM before investing in an engine package. My own solver landed in the site's code: 5 files, 556 lines, collisions between rotated rectangles, friction, bouncing and pushing apart elements that sank into each other (for the curious: SAT, an impulse solver, Coulomb friction, Baumgarte correction). I wrote it from the start to be moved into @flare-engine/dynamics one day.
The first version ran the physics live, in every browser frame, at a 1/120 s step, for visible elements only. Esc or a second click restored the page instantly.
What broke when real nodes started falling
The real DOM has its own rules. These are the ones I ran into on the way:
- The rest of the page takes the falling element's place. For an element to fall freely, you have to take it out of the normal page layout, and the browser immediately closes the gap it leaves. On my page, content below the fold jumped upward and the footer jumped. On top of that, nothing blocked scrolling. Locking scroll for the duration of the effect fixed that, but in Firefox the lock hid the sticky bar at the top of a scrolled page. In Chrome the same code worked correctly.
- You have to decide what counts as one piece. Splitting too finely broke a section title apart: the word fell on its own, and the thin line next to it was too small to simulate, so it hung in mid-air. Splitting too coarsely dropped the whole projects table as a single slab.
- An element moved out of its parent loses what it inherited from it. The word taken out of the section title lost its size, its capitals and its colour. A row taken out of a list got the default bullet the list had switched off.
- Other animations are already running on the page. Elements that the entrance animation had not revealed yet fell invisible.
-
A transform changes how an element looks, not how it behaves. A moved element can still be clicked and reached with the Tab key. The
inertattribute helped, but Tab still escaped to the skip link, which I fixed separately. - The page keeps living while the effect runs. The user clicks, navigates to another page, opens the command palette. On my page that led to crashes when removing elements, leftovers of the fall after navigating to another page, Esc clashing with the command palette, and a rare race that left the page frozen.
If your system has reduced motion turned on, the button does not appear at all. That is not a gentler version of the effect, it is no effect, and it is deliberate. The reason: even a softened effect moves every element across the whole screen, which ignores an explicit system setting, and for some people that kind of motion causes dizziness and nausea.
Computing the fall ahead of time
Live physics had another problem, unrelated to the DOM. I wanted closing the effect to play the fall back. But physics cannot simply run backwards: collisions are chaotic, and a reversed simulation will not retrace the same path.
So the fall is computed ahead of time (a bake) and played back like a recording (a timeline) that you can scrub. Rewinding is the same recording played from the end, so it looks like the fall run backwards, with no jump. After a browser test I also slowed the close down, because the first version closed too fast.
Built and rejected
The second version had a model that fit the "scrubbing time" metaphor on paper: two zones, a pause at the peak, a Restore button and a bottom bar for the controls. The third, from 2 July, is a deliberate partial reversal of two decisions from the second: one fall from start to finish, with no pause, and a column of controls on the right.
Why did I change my mind? The bottom bar covered the falling page. The UI looked ugly and was awkward to use. On paper everything looked fine; it only turned out badly in use. I fixed it after my own manual testing. A vertical column had existed even before the second version, so the third went back to it.
Earlier still there was a "time machine" plan. Almost all of it went: the rewind button with all its machinery, slow motion (0.25x and 0.5x), colour grading that I never built, and live physics, which the recording replaced.
The biggest piece I threw away was a separate page with an engine demo (CanvasKit). Built on 25 August, removed the next day together with the exceptions in the site's security rules (CSP) that it needed. The reason: /projects/* describes projects; it is not a place for demos. The engine's demos live on flareengine.dev.
What I never installed: planck.js
Since this is about 2D physics in the browser, someone may ask about this decision. I considered planck.js, a JavaScript rewrite of the well-known Box2D physics engine, but never added it and do not plan to. The reasons:
- my own solver already worked;
- a full Box2D port is too much physics for falling page elements;
- more code for every visitor to download;
- I keep external libraries to a minimum and did not want another one to maintain.
The decision is recorded in the engine's public docs: docs/design/dependencies.md, and PR #305 records that dynamics is the rigid-body answer and planck is not planned.
The solver moves into the engine
There is one detail I have to record here honestly. For a while the button said "built with my 2D engine" while the demo ran not a single line of engine code. The engine's public plan for moving the solver states it plainly as the goal: "This makes the claim literally true" (docs/plans/dynamics-lift-2026-08.md).
The order was: first I corrected the button copy (13 August), and only then moved the solver. The package appeared in the engine on 16 August, and on 25 August the portfolio's solver was replaced by @flare-engine/dynamics: exactly the same 556 lines, untouched since 1 July, left the portfolio.
The safety net was a determinism test written earlier, on 13 August. It drops 12 elements with the same random seed and checks at 21 points of the recording that each element sits in exactly the same place in two runs. A different seed must give a different fall. After the solver swap that test passed unchanged.
The old and the new solver do not compute identically, but almost: the largest difference in an element's position over 480 steps was less than a trillionth of a pixel (6.8 × 10⁻¹³). The first difference appeared at frame 77, and every element's final position matches to a thousandth of a pixel. It comes from the engine doing the same operations in a slightly different order, while the computer rounds the result of every operation on fractions. The page sets positions to a hundredth of a pixel anyway, so the difference is about 15 billion times too small to see. These measurements are recorded in my private repo, so here you have to take my word for it. What you can check publicly is the effect and the package: @flare-engine/dynamics on npm.
The fall's timeline later went the same way. The engine gained createTimeline in 0.4.10, built to this page's needs, and on 16 November the page switched to it and deleted its own implementation. Before deleting it, I ran both versions on the same data: 60 elements, 300 frames and 2001 sample points. The results were bit-identical, so the swap does not change a single frame of the fall.
Limits
- The determinism test compares two runs of the same solver version. When the package version changes, it will not tell you the solver changed. You have to diff the code separately. I did that for the bump from 0.4.5 to 0.4.12: the new feature that puts motionless elements to sleep is opt-in, and without it the solver computes exactly the same thing (
dynamicschangelog). Since 19 November the page turns it on: the bake stops when the engine reports every piece asleep (isAtRest), so from that day the fall is no longer identical to the earlier one. - The site is pinned to version 0.4.12 of the engine packages. (State as of 2026-11-16.)
- I give no figure for how much this effect adds to the downloaded code, and no performance figures. I did not measure them for this post.
- This runs on
/and/projects, not on the whole site, and it is not an engine demo. The engine's demos live on flareengine.dev.
If you want to repeat it
Start with real elements and transform, and only then think about physics. If you want to read about the engine itself, the earlier post is here: Flare Engine is open source.
Top comments (0)