Closed Thread Icon

Topic awaiting preservation: Calculating colors Pages that link to <a href="https://ozoneasylum.com/backlink?for=8367" title="Pages that link to Topic awaiting preservation: Calculating colors" rel="nofollow" >Topic awaiting preservation: Calculating colors\

 
Author Thread
Sam
Bipolar (III) Inmate

From: Belgium
Insane since: Oct 2002

posted posted 10-29-2002 14:03

Does anyone know how I can calculate colors in javascript? Suppose all my website colors are collected in one stylesheet. I want every row of my table to be a bit lighter then my background color, whatever that color may be. So I'm looking for something that can retrieve the background color of an element like a number and use it to calculate my new color?

InI
Paranoid (IV) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 10-29-2002 14:19

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

Sam
Bipolar (III) Inmate

From: Belgium
Insane since: Oct 2002

posted posted 10-29-2002 15:23

The calculation part looks ok for me, thanks alot. The only thing I (still) don't know is how do I get the background color of an element, knowing that this color is defined in a stylesheet? Which method/property or whatever do I use?

Dracusis
Maniac (V) Inmate

From: Brisbane, Australia
Insane since: Apr 2001

posted posted 10-29-2002 15:44

There are several ways to do this depending on the element type and browser.

The easiest way would be to give the element an "id" so you can refer to it through script easily. Then you can use:

document.getElementById("myElement").style.backgroundColor

Which is a readable and writable property, so you can use it to set the background colour too. Although for moust browsers you'll need to set the style inline (in the element's tag itself) or it will return a blank value from the above mentioned address unless you've perviously set it using that address.

There are ways of doing this if you don't want to set the style inline but they differ between browsers and for some (namely opera) it's just not possible.

That what you were after?



[This message has been edited by Dracusis (edited 10-29-2002).]

Emperor
Maniac (V) Mad Scientist with Finglongers

From: Cell 53, East Wing
Insane since: Jul 2001

posted posted 10-29-2002 19:07

Added to FAQ:

How do I calculate colours with JavaScript?

___________________
Emps

FAQs: Emperor

« BackwardsOnwards »

Show Forum Drop Down Menu