Airport departure board or split-flap display effect with JavaScript

 

Split-flap display
In this tutorial I’ll show you how to achieve the split-flap display (aka airport departure board) effect with JavaScript. Now available also as Jquery plugin

Before we start with the coding, let my explain really quick what we’ll do. For the purpose of this tutorial I’ve prepared a table with strings. My if-act (effect) will be executed on mouse over and stopped on mouse out if necessary. Let’s get started!

When you look at an airport departure board what do you see? Yep, flipping characters! So lets begin by defining the chars we want to flip in a long string.

Let’s put this variable in the body of a constructor function that will be our flipper class.

As you can see the constructor has 1 parameter that is the object whose innerHTML we’ll flip. In order to do that we need the chars of the innerHTML in an array. Chopping a string to array is simple with the method .split() of the String class. I also use another two arrays. The first I called indexes holds the indexes of the chars that need to be flipped. The other one is the array that will be flipped and it holds indexes of chars in our chars variable. With a little bit of initialization we come to this:

We’ll come to the rest of the variables in a moment but first take a look at the initialization loop. When the if-act starts every char from the innerHTML will start to flip from the char at position 0 in chars (#). I need all of them to start rolling and that’s why I push all indexes in the indexes array. Notice that indexes in this variable correspond to those of both the textArray and the cia. The flipping will be handled by a function called roll(). In its body there is a loop trough indexes. For every index I increment the value in cia and thus go another char forward from chars until I reach the char that is at the same index in textArray. In that case I exclude the index so that it’s not flipped anymore. The function looks like this:

The repaint function assembles the string and puts/shows it.

The roll method is called every 70ms by setInterval(). That’s what I need the this.interval variable for.

_this holds the instance scope. And the code of the whole class goes like this:

You can check out the demo here: split-flap display if-act

The second table holds another version of my class which starts to flip the chars one by one.

Tips and Hints: You can control the speed of the if-act by reducing/increasing the time in setInterval() and/or the number of the chars in chars.

For questions, suggestions or requests use the comment section below.

 

18 Replies to “Airport departure board or split-flap display effect with JavaScript”

  1. I discovered your weblog internet site on google and check some of your early posts. Continue to maintain up the quite very good operate. I just additional up your RSS feed to my MSN News Reader. Seeking forward to reading far more from you later on!

  2. Hello there, simply became aware of your weblog via Google, and located that it’s really informative. I am gonna watch out for brussels. I will appreciate if you continue this in future. Lots of people might be benefited from your writing. Cheers!

  3. I love your blog.. very nice colors & theme. Did you create this website yourself? Plz reply back as I’m looking to create my own blog and would like to know wheere u got this from. thanks

  4. Good day! I know this is kinda off topic but I’d figured I’d ask. Would you be interested in trading links or maybe guest authoring a blog post or vice-versa? My blog addresses a lot of the same subjects as yours and I feel we could greatly benefit from each other. If you are interested feel free to send me an e-mail. I look forward to hearing from you! Great blog by the way!

  5. Maybe there is a problem with the CSS here? I can’t make out anything here without highlighting it with the mouse, because it’s all green. I’m using Chrome if it helps.

  6. Oh my goodness! an amazing article dude. Thanks Nevertheless I am experiencing subject with ur rss . Don’t know why Unable to subscribe to it. Is there anybody getting an identical rss problem? Anybody who knows kindly respond. Thnkx

  7. I was very pleased to find this site.I wanted to thank you for this great read!! I definitely enjoying every little bit of it and I have you bookmarked to check out new stuff you post.

Leave a Reply

Your email address will not be published. Required fields are marked *