View Full Version : JasaScript, CSS and reading color properties
12-13-2005, 02:08 AM
I've written something, but it's hackish.
function rgb(r, g, b)
return (r<<16) + (g<<8) + b;
if(s.charAt(0)=='#' && s.length==7) // Opera
if(s.charAt(0)=='#' && s.length==4) // IE
if(s.substring(0, 3)=="rgb") // Netscape / Mozilla
alert(s); // WTF
[...] var myColor = colorToInt(document.getElementById("myelement").style.color); [...]
Is there a proper way to do this?
12-13-2005, 04:58 PM
That's not bad. What is your object in this? If the color is set in the stylesheet, through inheritance or via attribute, this:
var myColor = colorToInt(document.getElementById("myelement").style.color);
will not pick it up. Also, what will you do with this integer once you have it?
12-15-2005, 12:56 PM
Well that's not much of an issue, that particular line I wrote out of my head to show the use of colorToInt.
My goal was to fade a page's background and contents to white, but keeping it proportional.
It's supposed to be for the loading intro of my homepage. You can find a working example of it here: http://maplecenter.net/thecybershadow/ (temporary URL).
12-16-2005, 07:24 AM
Just a tip for simplifying your full code on this, which looks quite impressive and will provide hours of enjoyment trying to fully follow - To get the hex color value of the output of colorToInt(s) or any color represented as such an integer as this and other functions in your code produce:
Wouldn't it be easier to return an array of three values?
12-16-2005, 06:54 PM
That isn't quite correct. Suppose the value is less than 100000? Then the number would have 5 or less digits. Which is NOT what we want.
If you'll read fader.js on my site further, you'll find this function:
var s = i.toString(16)
12-16-2005, 07:48 PM
If you'll read fader.js on my site further, you'll find this function: . . .
. . . which looks quite impressive and will provide hours of enjoyment trying to fully follow . . .
Powered by vBulletin® Version 4.2.2 Copyright © 2014 vBulletin Solutions, Inc. All rights reserved.