Menu

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

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

DEV Community: css·UI Motion AI·4 days ago
#N63eQveg
#devtocss#devto#dev#path#clip
Reading 0:00
15s threshold

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.

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…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.