So if I have a text “Click Me to Brighten” that has CSS color property of some dark green hex color like “#00801a” I want to make it so that when I click on it, it makes it a lighter green. Likewise, if it were some blue color, clicking on it would make it lighter blue. Basically I want to know if there is a way to change the css color without knowing the actual color.
Share
Converting to HSV to change the brigthness
See the full code example on jsFiddle
This version uses
HSV. I convert the originalrgbvalue tohsvand change the value ofvto get a lighter color. I gotRgbToHsvfrom Pointy answer, I just added a little fix for gray. And I gotHsvToRgbon this websiteWhen the page loads I am getting the
rgbconverting intohsvchanging thevvalue, convert back torgband change thecssof the element with the new value.Result:
Increasing color values by highest color
See this example on jsFiddle
The
divson top represents the dark colors (rgb)#801A00,#00801A,#1A0080and#D2D2D2The
divson the bottom will get the light color from the dark.When I click a dark div it will retrieve the
background-color, split the values and send to the functionLighthen. This function will make the color more light.When the dark div is clicked, the new color is calculated and changed on the correspondent
div.Resulting in