Animated Pitchbars

Another project for a contract that I thought I would post, An animated pitch bar. Originally created for theamm.org it was used for give short bits of information on their service, but it can be used for anything. Instead of breaking it down and going through it section by section, I’m going to try this a different way, first I’ll post the code as it is used, then I’ll explain the reasoning behind it. Heres the scripting you’ll need.

Snipplr: http://snipplr.com/view/54562/animated-pitchbars/

First we use jquery to load this once the document is complete (since the script needs the appropriate HTML to be ready to work properly). The function starts with variables, the first line of them are ones for easy modification, pitches in the number of pitches it will show at once, and the shortdelay/longdelay is the delay between animating individual and pitches and the delay between animating the last displayed pitch and starting from the top again respectively.

After that there is a while statement, this takes the appropriate pitch and wraps each element around a span for animation purposes. Then it gets into the main scripting and animation section.

The each function runs through each of the spans and starts the animation on it. First is fades the current value out, it inserts the new pitch, pre-set at 0 opacity, and fades it in span-by-span. Once the loops is complete (using the n3 variable to count and compare) it runs a couple checks, first if it’s on the last pitch being displayed or not, if it is the last one it reset the pitch display counter to 1, if not it adds one to it. Then it check to see if it’s on the last pitch in the list of all pitches, again, if it is it resets it to one, if not it adds one. Finally it checks to see what it’s going to be doing next. If it’s going to start from the first displayed pitch again it waits for the long-delay value and starts the script again, preserving the pitch number and the pitch display location, other wise it waits the shot delay time and again send the appropriate information out.

With this setup the script will run forever, looping when needed. It does not require a even number of pitches or a specific pitch/display ratio and the script doesn’t need to be changes if you add or subtract new pitches to you list. It does require some HTML formatting though, which should look like this.

  • Pitch 1
  • Pitch 2
  • Pitch 3
  • Pitch 4
  • Pitch 5

Snipplr: http://snipplr.com/view/54562/animated-pitchbars/

The first section is the list of pitches, stored in an un-ordered list with the id “pitches”. Each pitch simply goes in a list item. Theres nothing more to creating the list of all your pitches. The display goes inside the divs. The class pitchbar is my own simply for formatting (it’s not required if you don’t want it there) the other one, activepitch# is the area where the the current pitches will be displayed. The “#” is for each pitch that you display at a time from 1 to your max, for example the code above was a pitches of three, so I have 3 divs; activepitch1, activepitch2, activepitch3. The example at the link blow has 5 divs and a pitches value of 5 as well. This was set up this was as opposed to simply showing the individual list items because at the time of creation nobody working on the design was sure where they might go or what level of customization of those pitches we might want.

I’ve made an example using of this in action using the HTTP status code, you can see it on the Animated Pitches Example page. If you have any questions or use this in your own project let me know in the comments. I’ll try and help people out with implementation and modifications as I’m sure I’ll always find a new use for the code myself.

Inline input labels with animation

This last week I’ve been doing a lot of work making a new homepage that looks like twitters, as well as modifying some things on the rest of the site to try and give it a cohesive look. While most of the site is still on the to do like (it’s a fairly large site) the new homepage is done (you can see it at theamm.org, no promises it hasn’t been changes as the owner has a copy of CSS Edit and it not afraid to use it) and I think it met the goal. One of my favorite (non specialized) features is the animated inline input labels. Because it’s a great, simple implementation I decided to post it here.

First, the input are formatted a very special way, don’t worry it’s basic and easy to implement. First, the input for firstname:

Snipplr: http://snipplr.com/view/53928/inline-labels-with-jquery-animations/

The input is obvious, as is the label, the last div, with the class .inputerror.firstname is some specific code for inline displayed error messages, I may make a post about them if there is any interest. The trick to this is the CSS, the div.inputbox is the thing that actually looks like the input, and the true input has no border or background. The label is moved over the input box. Because of this it’s important to have the label properly formatted with the for="" element pointing to the appropriate input field.

The CSS that makes that look right is below, it’s the code used in the example (link at bottom) as the code used on that site is more than a little messy (to many people playing around with it).

Snipplr: http://snipplr.com/view/53928/inline-labels-with-jquery-animations/

Obviously that has some styling for looks, which is fully changeable based on your individual implementation, the important stuff is the display, overflow, and the margin-top on the .inputbox label, as well as the previously mentioned background in the .inputbox input style. You’ll notice that the inputbox doesnt have a width or a height (except where limited by the actual input inside it). That because thats all set via the individual inputs so you can vary it from input to input depending on what will go in it (just like the example has set up).

The last bit is the scripting, in this case jquery was used, but it should be convertible to any other javascript library, or straight javascript itself, It’s only in jquery here because I use jquery for nearly everything because it’s fast, stable, and feature-full. In this case it’s a function called at load although it can be called in any as long is it’s sub-function tun on keyup and/or keydown.

Snipplr: http://snipplr.com/view/53928/inline-labels-with-jquery-animations/

What this scripting does is bind the sub-function keyupdown on both the keyup and keydown. The reason it’s done on both is because it’s more reliably in always running that it is when you just do on up or down. The first first checks if there is a value to the input, if not it will reanimate the label back in, with a simple fade in the case, but you do have full control over how it does it. Then, if there is something in the input it will fade it out, in this case by pushing it right while fading out. Once a label is completely faded out it is hidden so it won’t interfere with normal operation of the input box (like selecting or double clicking). It also makes it visible again before fading it back in.

All three parts put together make a nice animated inline label like the ones on the Inline input labels with animation example page. It’s been tested in IE and on mobile devices and seems to work fine albeit with slow or no animations on mobile devices. There was some weird graphical things in IE on the test site but I believe it was due to the font-weight and IE’s lack of fon’t smoothing that caused it.

If you’ve found a great use for this, or have an questions or would like some help with modifications or implementation on your specific site leave a comment below.

100% width text area with adjacent button

Long time to post, between being sick and doing a bunch of really boring coding work nothing of value to post has come up recently, until now. Last week I was working on a contract where they have the entire layout as a series of tables set to 100% width (I know tables, how retro). Anyway I was trying to do something I had done hundreds of times before on their site, a text area thats 100% wide (so it flexes with the width of the page) that has a button next to as (as opposed to below it like would naturally happen). After spending some time on it i figured it out and decided I would post it here on the weekend so I would always be able to find it. Come today and wouldn’t you know it I forgot how I did it, so I played around a bit and found a solution. It’s not the same as the one I used for them but the end effect is the same. First it requires you to but some code around your input (it’s never that simple), a mini example table is below.

Enter Text

Snipplr: http://snipplr.com/view/52532/100-width-text-area-with-adjacent-button/

The last 2 empty table cells are not important, there just there because thats the same style that the contract sets everything up with. Anyways as you can see you have to wrap the entire input in a div, then just the text area in a div. Another thing you have to do it give your button a width, I usually use 95px since it seems to fit the majority of buttons out there (after all buttons names are usually things like “Submit” or “Load” not “Press here to do the thing you want to do”). That width of the button, along with any margins or passing you add to it to make the format clean, as then added as right padding to the cell this div cluster is placed in so in this case 95+5 to make the final product look clean is a nice round 100px. That code there is paired with the css below (it’s normal CSS here but it works just as well being all inline).

Snipplr: http://snipplr.com/view/52532/100-width-text-area-with-adjacent-button/

That css code prevents wrapping and plays with margins (equal to the amount of padding above, button width + margin) to get a nice clean look when your done. The simplest way to description what it does it in throws the button off the end, outside of the box, but the box is made shorter (by the inline padding added to that cell) to compensate and move it look as if it’s in the box.

One thing to note, if your going to use jQuery to pull values from the box laters you probably want to avoid the child selector “>” to make it easier, just use a space as it acts as a simple inside selector going all the say down when looking for elements, in this example that text area could easily be selected with #(“table input[type=’text’]”).

You can see it on the worlds more boring example page here: 100% width text area with adjacent button.

I know this is a poor way to do this, and if I run across any of my old code that does it in a better way I’ll update according, but this effectively works and I can now at least reference this myself later, even if nobody else is ever helped by it. If you know of a better way to achieve the same thing please comment.