Using javascript with or without Jquery, I need to a create a gradient of colours based on a start and finish color. Is this possible to do programmatically?
The end colour is only ever going to be darker shade of the start colour and it's for an unordered list which I have no control over the number of li items. I'm looking for a solution that allows me to pick a start and end color, convert the hex value into RGB so it can be manipulated in code. The starting RGB values gets incremented by a step value calculated based upon the number of items.
so if the list had 8 items then the it needs to increment the seperate Red Green Blue values in 8 steps to achieve the final colour. Is there a better way to do it and if so where can I find some sample code?
I created a JS library, RainbowVis-JS to solve this general problem. You just have to set the number of items using
setNumberRange
and set the start and end colour usingsetSpectrum
. Then you get the hex colour code withcolourAt
.You are welcome to look at the library's source code. :)
The xolor library has a gradient function. This will create an array with 8 colors in a gradient from a start color to an end color:
See more on github: https://github.com/fresheneesz/xolor
Not such mighty but in most cases working and you do not have to include any other libraries except jQuery for the following code:
HTML:
JavaScript:
This should make an div that contains a rainbow. See http://jsfiddle.net/rootandy/54rV7/