HighDots Forums  

Recovering RGB values from a colour attribute

JavaScript discussion (multi-lingual) JavaScript discussion (alt.comp.lang.javascript)


Discuss Recovering RGB values from a colour attribute in the JavaScript discussion (multi-lingual) forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
David Robinson
 
Posts: n/a

Default Recovering RGB values from a colour attribute - 08-03-2004 , 03:06 AM






I feel this ought to be an easy one, except that nothing I do will work and
I can't find any help in my books!

I have the statement

mycolour=y.style.backgroundColor

which successfully picks up the colour of an element, and allows me to apply
that colour to some other element. But I now want to make smooth
adjustments to the colour by accessing the individual RGB components of
"mycolour". Can anyone tell me what Javascript statements I need?

David Robinson



Reply With Quote
  #2  
Old   
Andre Herbst
 
Posts: n/a

Default Re: Recovering RGB values from a colour attribute - 08-07-2004 , 02:16 PM






David Robinson wrote:
Quote:
I feel this ought to be an easy one, except that nothing I do will
work and I can't find any help in my books!
The color code consists of the RGB in hexadecimal:

#00aaff would have following RGB-Values:

R = 00 = 0
G = aa = 170
B = ff = 255

To solve your problem you need functions that can convert hexa<>decimal
numbers:

You can write this script by yourself or you can use existing scripts:

http://www.skyzyx.com/scripts/convert.php




Reply With Quote
  #3  
Old   
David Robinson
 
Posts: n/a

Default Re: Recovering RGB values from a colour attribute - 08-09-2004 , 02:12 AM



Hi Adrian and Andre

I think I've answered this one for myself. The problem seems to be that if
I declare an element to be coloured red, then the stored attribute for that
element appears to be the 3-character string "red", and not, as one would
have expected, the string "#FF0000". It stands to reason then that there is
no way of subsequently processing the colour attribute in the way you
suggest. On the other hand if I actually declare the original colour as the
hex string "#FF0000", then everything works fine.

Quite naturally I would have expected the colour "red" to be translated into
the 6-character hex string immediately the browser encounters it, but it
seems that ain't the case!!

Many thanks for your efforts to answer my problem.

David

"Andre Herbst" <moorkonig (AT) compuserve (DOT) de> wrote

Quote:
David Robinson wrote:
I feel this ought to be an easy one, except that nothing I do will
work and I can't find any help in my books!

The color code consists of the RGB in hexadecimal:

#00aaff would have following RGB-Values:

R = 00 = 0
G = aa = 170
B = ff = 255

To solve your problem you need functions that can convert hexa<>decimal
numbers:

You can write this script by yourself or you can use existing scripts:

http://www.skyzyx.com/scripts/convert.php





Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.