One thing I've seen in some Desktop applications is the ability to change the color of text as the background changes -- to effectively have multiple colors on a single character. I've seen this most commonly with progress bars that display the percentage inside the bar. Generally a darker background color will be used as the progress bar color, and as it progresses, the dark color doesn't contrast enough with the dark text, so the text color changes as soon as the bar overlaps with the text. This image should explain what I mean:
As you can see, the text is black when it's at 0% -- when there is no dark background. When the background image fully progresses to 100%, the text is completely white. But in the middle, as you can see at 50%, the text is half black/half white, and it's actually split on the "0" character in this example.
Is there any way to do this at all on a webpage? CSS, Images, Jquery, otherwise? (Preferably not Flash or a Java applet though -- I'm really wondering whether an HTML-based solution is possible.) Thanks!
Here's another implementation: http://jsfiddle.net/3rcav4s4/.
HTML:
CSS:
JS/jQuery:
This is really interesting actually. Here is your progress bar. Works fine in IE5.5+ and Safari 5 (browsers that I tested).
Uses system colors. :D
Visualization here
Note that I used
setAttribute
to assign the value to the progress bar using a custom attribute name.Modifying the script for real progressing
The above example is just a dummy progress bar, because it uses a timer to increase the value. To do real progressing you have to modify the script a bit. You can change the function
progress
so that it adds the value to the current value, or you can do it so that it sets the value. The second approach is probably what you want to use.You can leave out
value = value > 100 ? 100 : value < 0 ? 0 : value
if you make sure that the value passed to the function is between 0 and 100.Test it here
Edit:
I changed
innerText
toinnerHTML
so that it works in Firefox. I wasn't aware of this. I also changed in the CSSdisplay:inline-block
todisplay:block
. I know this way you can't have the progress bar inline anymore, but this makes it work in Netscape 9.I'll get you started:
div
s). Set their size to the full width they would be if they were at 100%.div
and increase the width of the parent on every percentage increase. Position the parent above the black/white bar.That will simulate the same effect without having to manually paint half a character. It will be difficult in CSS because you will have to position one over the other.
The benefit of doing it this way is that you can easily display half-painted characters. There is already a jQuery progress bar you can use, though.