Bits and Pieces

Insightful articles, step-by-step tutorials, and the latest news on full-stack composable software…

Follow publication

Creating Morphing Animations with CSS clip-path

Mikael Ainalem
Bits and Pieces
Published in
8 min readApr 13, 2020

--

Photo by Thomas Renaud on Unsplash
Video of the demo Play Pause Button

What is morphing?

Morphing in SVG

The two steps of creating the morphing effect

Modeling the play/pause button

Half the play symbol
Zoomed-in view of the nodes in the half of play symbol
// Play/pause model
<svg ...>
<circle ... /> /* red circle */
<path d="..." /> /* Half play symbol */
<path d="..." /> /* Half play symbol */
<path d="..." /> /* Pause bar, left */
<path d="..." /> /* Pause bar, right */
</svg>

Making things move

What is this clip-path morphing?

.animated {
transition: clip-path 500ms;
}
.animated {
transition: clip-path 500ms;
clip-path: polygon(...); // start state
}
.active .animated {
clip-path: polygon(...); // end state
}
<div class="animated" onclick="this.classList.toggle('active')">
...
</div>

Dev Tools FTW

Manipulating shapes in the roles editor

Moving to CSS space.

/* From SVG */
<svg ...>
<path d="..." />
</svg>
/* To CSS */
<div style="clip-path: polygon(...)"></div>
star figure to convert from SVG to CSS
<path d="M 73.924957,90 49.42372,75.971326 24.48224,89.124336 29.669821,60.42209 10,39.681618 37.707342,35.971327 50.492205,10 62.4287,36.409157 90,41.098468 69.669822,61.130517 Z" />/* Converts to */<div style="clip-path: polygon(73.92496% 90%, 49.42372% 75.97133%, 24.48224% 89.12434%, 29.66982% 60.42209%, 10% 39.68162%, 37.70734% 35.97133%, 50.4922% 10%, 62.4287% 36.40916%, 90% 41.09847%, 69.66982% 61.13052%);"></div>

A glimpse into the future

The source

The Play Pause Button demo on Codepen

TLDR;

“Uncommon thinkers reuse what common thinkers refuse.”

— J. R. D. Tata

Exploring shared React components in Bit.dev

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Published in Bits and Pieces

Insightful articles, step-by-step tutorials, and the latest news on full-stack composable software development

Written by Mikael Ainalem

Enthusiastic about software & design, father of 3, freelancer and currently CTO at Norban | twitter: https://twitter.com/mikaelainalem