Switching layouts without teleporting.
A view switcher that rearranges the same items into a grid and animates each from where it was.
The trick
This is FLIP by hand: I record every item's rect, switch the layout class, then animate from the old offset to none.
Reduced motion skips the animation and leaves the layout change.
function setMode(m,anim){const a=new Map(items.map(e=>[e,e.getBoundingClientRect()]));
SG.onclick=e=>{const b=e.target.closest('button');if(b)setMode(b.dataset.m,true)};
Where I'd use it
Gallery and file views
Items fade to .4 opacity as they travel, which hides the odd moment when sizes change mid-flight.
The prompt for this one is free: uimotion.app.

Top comments (0)