Change the Hue of a RGB Color in javascript

前端 未结 2 1587
天涯浪人
天涯浪人 2021-01-31 23:00

Similar to this (how to increase brightness) I want to change the Hue of a RGB (Hex) Color.

Say changeHue(\"#FF0000\", 40) returns \"#FFAA00\"

2条回答
  •  南笙
    南笙 (楼主)
    2021-01-31 23:29

    If you're not afraid of libraries and a few kb won't ruin your project, you could try sc-color rather than reimplementing the wheel...

    Here's a jsfiddle using sc-color. The crux of the code is here:

    var c = sc_color("#FF0000").hue(40).hex6();
    $("#test").css("background-color", c);
    

    Disclosure: I'm the author of sc-color

提交回复
热议问题