Wobbling Vertical Progress Bar
I learned how to build a neat, dynamically sized vertical progress bar with cross-bars in This Question.
Now, I want to make it fun!
The bar's wobble function should:
- take 4 parameters:
element
,height
,speed
, &random
- wobble the
element
height percentage with a customizable, randomized factor - keep track of the elements's true height, which can change at any time!
- use an event (in the Fiddle, I supply an input and button) to set the true height to a new value, and animate to that height.
I'm looking for the simplest answer. Please explain how you did it, so that we JS newbies can learn tricks! Posting a Bounty of +50 to the best answer.
Bonus:
- change the bars's background color value based on the bar's true height. Red is 0%, Yellow is 50%, and Green is 100%;
If your function does this too, I'll add a +100 Bounty to your answer instead.
I'm asking this question because I don't know how to do this yet. But, I'm going to try it from what I've learned so far, and keep my progress posted here.
Don't think StackOverflow is meant for these kind of 'questions', but oh well, felt like it, so made a far more extensive answer than a sane person would.
Let me start with a couple of technologies I incorporated and their justification
X-Tags, X-tags is a Web Components Custom Element polyfill developed by Mozilla. It allows us to write something like
And then do
Cool right? This however means you will first need to read the documentation here. Before you will be able to understand the code.
y=sin(t)
and a more complexed dampened wave. One could easily add other waves as well, but these seemed to be the most reasonably interesting ones.As the code itself is over 200 lines long I will refrain from posting it here and you can find it on this jsfiddle.
So here's my JSFiddle take on it.
Comments should be self explanatory. I had to add JQuery UI for the animation effects with easing. I'm not sure what you meant by
random
, but speed should be all you need to change.Sorry, no animation in the screenshots.
Really enjoyed playing with this, so thank you :) I took a different approach but with much less code. I think I went a bit overboard with the colors, if needed I can change it back to red yellow green.
http://jsfiddle.net/3wN77/23/