Answer the question
In order to leave comments, you need to log in
Change color intensity with jQuery?
Hello dear Habrahumans.
Yesterday, a friend asked me to make it so that with the help of a slider on the site it would be possible to change the color intensity in the block.
Dragging the slider is not a problem, but I'm stuck with the intensity.
Can you tell me how to change the color intensity using JS?
It is advisable to do without plugins!
I just haven't come across this before.
Thanks in advance!
Answer the question
In order to leave comments, you need to log in
CSS3 has HSL color notation . To decrease the intensity, you need to decrease the saturation (saturation). For IE less than 8, you can write color in RGB, converting it from HSLa with javascript .
The easiest option is to change the css property "opacity", like this:
$('#element').animate({opacity: "0.5"}, 500);
Well, for full compatibility, you can use the HSL2RGB converter www.codingforums.com/showpost.php?p=54172&postcount=2
Compatibility is optional, this is for modern mobile browsers"!
code.google.com/p/flot/source/browse/trunk/jquery.colorhelpers.js
Used in particular in flot.
It works approximately like this,
$.color.parse("#fff").scale('rgb', 0.25).add('a', -0.5).toString()
it allows you to conveniently work with color, changing the values of the channels together or separately, to an absolute or relative value.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question