0

As per LESSCSS documentation, i can apply saturation like below in LESS file.

background-color: saturate(#A0F809, 25%);

But i am going to populate a list in javascript and each list item has it's own background color. And i need to apply hover color by saturating 25% from it's background color. How can i do this in javascript / jquery?

I tried LESS parser. But it expects me to pass css class, it is not accepting css style.

This works:

parser = new(less.Parser);
parser.parse('.class{background-color: saturate(#CD6667, 25%)}', function(err, tree) {console.log(tree.toCSS())})

But not this:

parser = new(less.Parser);
parser.parse('background-color: saturate(#CD6667, 25%)', function(err, tree) {console.log(tree.toCSS())})
2
  • Can you set up an example in a jsfiddle? also, what's the error message? Commented Sep 12, 2013 at 11:41
  • you can directly try above code in console from lesscss.org Commented Sep 12, 2013 at 13:42

1 Answer 1

1

This works. You can call most of these functions like below.

color = "#235689";
color = color.replace("#", "");

//get less color object
color = new less.tree.Color(color); 

//saturate it 50%
color = less.tree.functions.saturate(color, {value: 50}).toCSS();

now color returns 50% saturated color.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.