Javascript - Sort rgb values

前端 未结 2 2056
攒了一身酷
攒了一身酷 2020-12-13 16:22

Using javascript/jquery, I want to sort an array of rgba values to the colours of the visible spectrum. By doing this, like shades should be bunched together. Is there a plu

2条回答
  •  南方客
    南方客 (楼主)
    2020-12-13 17:01

    Disclosure: I'm the author of the library recommended below.

    If you don't mind using a library, here's a much more concise version of Oriol's detailed response. It uses the sc-color library:

    var sorted = colorArray.sort(function(colorA, colorB) {
        return sc_color(colorA).hue() - sc_color(colorB).hue();
    });
    

提交回复
热议问题