Stay up to date with new components!
Error!
Success! Thanks so much 🄰

Web Components On Fire

View the source

Split Flap

We live in the 21st century and we no longer have signs that work like this:

The split flap board in Philadelphia’s 30th Street Station, which was removed in 2019.

This board, while obviously inferior to a digital display in many ways, has a lot of appeal. Instead of projecting pixelated LED light into your retinas, it’s actually moving and reflecting natural light. There’s something to the infinite resolution on this thing.

As an ode to the train stations of my childhood, I bring you a skeuomorph split-flap web component:

Split Flap

If you want a text animation that lasts way too long and will surely kill all your K.P.I.s, you can do it in two steps using the <hotfx-split-flap> custom element. First add this script to your page:

Then just wrap your message in the custom element, like so:

<hotfx-split-flap>Your message here</hotfx-split-flap>

That’s all it takes and the transition will start as soon as your readers scroll the component into the viewport.

Set Some Attributes

The custom element accepts a few attributes to control the output:

Here’s a playground for you to build your own split flap board.

Custom Split Flap
50 1000
duration= 150
1 30
width= 20
1 10
height= 5

If you don’t specify height and width for your board, the element will take the height and width of the first message inside of it. If you later change out the message, it will be truncated to fit in the same grid. The first demo gets around this by creating a new element when the text doesn’t fit.

How Does This Even Work?

To get these flaps flappin, the web component splits the string of text inside of it and makes four copies of each character, split into the current and next characters in the animation each divided in half using clip-path. Then to do one flap, it simultaneously rotates down the top half of the current character and the bottom half of the following one.

After one animation, the element will swap out the characters and start the next animation and so on. A key CSS property is backface-visiblity: hidden, which keeps the letters from showing through to the other side of their elements.

Big, Slow Split Flap

Style It!

This wouldn’t be much fun if we couldn’t make it look totally weird. The main way to get your hooks into this thing are with the ::part() pseudo elements. There are a lot of them, so here’s a list for you:

That’s a lot of elements so you can do some pretty neat stuff.

Styled Split Flap

Internationalization

There’s another attribute named characters which lets you control the alphabet of characters shown on the flaps. Here’s one in Russian, showing the titles of some of Tolstoy’s novels.

Tolstoy’s Novels

I’m swapping out the message on the board every few seconds using a simple callback scheduled with setInterval. Use the source, Luke.

Rolling Forward

There’s not much of a roadmap for this component, but I’m open to ideas. I would love to see whole words shown on one flap just like the destinations in the video of the train station board at the top of the post. An event that fired when the animation finished might be useful for chaining these animations together as well.

Can you think of other improvements? Of course, if you have bugs or feature requests, please file a new issue on GitHub.