15 March 2007

Use JavaScript to progressively fade text color and size

Progressive fade color and progressive change in font size is a great way to show importance of data …

I used this technique on the ratings of css galleries page and if i did that by hand it would have been a pain especially with reshuffling…

example…

lets play … (click on each)

reset all | color p | color link | size li

the explanation …

I am sure some of the libraries out there do this kind of stuff, but i find doing it your self is the best way to learn… the code is well commented, so i will just explain how to use it … feel free to ask any questions…


// function do_step_style
// @container
// @element_to_style
// @sub_element_to_style
// @start_val
// @end_val
// @style_prop
// @reset
container
The container ID that has all the things you want to be styled
element_to_style
The element you want to have the styled applied to
sub_element_to_style
A sub element to apply style to (a child of element_to_style … null if none)
start_val
Starting value if color then 6 digit hex (#333333) or if fontSize then em unit (1)
end_val
Ending value if color then 6 digit hex (#333333) or if fontSize then em unit (1)
style_prop
Property to style (color or fontSize) - you may want to add more…
reset
Optional … remove styles … set to true

the usage …

do_step_style('progressive','li','p','#666666','#cccccc','color') - color p
Find container "progressive"
Find all the "li" tags inside container
Find the FIRST "p" tag inside "li"
Color from #666666 to #cccccc
do_step_style('progressive','li',null,'1.5','.9','fontSize') - size li
Find container "progressive"
Find all the "li" inside container
Decrement "li" size from 1.5em to .9em
do_step_style('progressive','li','a','#cf852c','#cccccc','color',true) - reset ONLY a
Find container "progressive"
Find all the "li" tags inside container
Find the FIRST "a" tag inside container
Remove the color property

the source …

progressive-fade.zip

 

comment

what they saidwho said it

Doesn’t work under IE7 for FireFox

2007-03-15
Don Withrow

That’s weird i have tried both IE7 and Firefox on PC… and Safari and Firefox on the Mac … and it works ?

2007-03-15
DannyB

I am playing a game thats runs under javascript can someone please tell me how i can change font while in the chat window? I have tried HTML codes which do not work. Any suggestions

2007-09-23
Bridget

Great tips

Thanks,
Sam

2008-06-26
sam


note: you can only submit after you hit preview


nuff-respec is a weblog written by daniel bulli a senior web programmer in boston, ma.
more >

contact | resume | profile

recently :::

diversions :::

beSlimed - Mootools game
Cool little game done in my favorite javascript library...
First Magazine
A Jamaican Magazine on the web ... very clean ... now i need to explore the articles ...
The Afflicted Yard
Love to see when there is Jamaican stuff out there... nice thoughts and clean design ... just don't look on the source code ...
BugMeNot
What a wonderful service of passwords for sites that want pointless registrations...
you still want more »