PHP - Rotate a HEX color value (eg swap all colors with "next" hex)
I have a set of hex values in an array in PHP. On my page, I have a slider which the user can "slide" to retur开发者_StackOverflow社区n a value between 1-100. I want to then, based on this slider value, swap all the colors in the array based on the colors "next" color based on the position in the array. An example of the same sort of thing would be like in Photoshop where you can rotate the hue of a layer. I want to do the same thing, in PHP, for a hex value.
Any clues?
This could easily be done using a library like jQuery.
Assuming that you have your slide with an id="slider" which returns a value from 0 to 99 and that you already have initialized a variable with all the colors and that the div in which you want to show the color is named #colorDiv:
var colors = ['#ffffff', '#ffffcc', 'ffffaa']; //With all the 100 colors
$('#slider').on('change', function() {
$('#colorDiv').css('background-color: '+colors[$('#slider').val()]);
});
Should do the trick.
精彩评论