DEV Community

UI Motion AI
UI Motion AI

Posted on

How I built a border draw pay with plain CSS and a little JS

The border draws a lap, then the inside fills.

A pay button whose border draws a full loop, after which a clip path wipes the done text in from the left.

demo

The trick

The outline is an SVG rect with pathLength 1, so dasharray 1 and dashoffset 1 to 0 draws exactly one lap.

The fill starts 40ms before the loop ends, using a calc delay on the clip-path transition.

A gray rect underneath shows where the border will go.

.r1{stroke:var(--fx-ink);stroke-dasharray:1;stroke-dashoffset:1;transition:stroke-dashoffset var(--dur) linear}
.on .r1{stroke-dashoffset:0}
.fill{position:absolute;inset:0;display:grid;place-items:center;background:var(--fx-on);color:var(--fx-on-ink);clip-path:inset(0 100% 0 0);transition:clip-path 260ms var(--fx-ease) calc(var(--dur) - 40ms)}
.on .fill{clip-path:inset(0)}
Enter fullscreen mode Exit fullscreen mode

Where I'd use it

Payment and confirm buttons

Normalizing the path to length 1 means the draw works at any button size without measuring.

The prompt for this one is free: uimotion.app.

Top comments (0)