前台渐变色
.linear-break{
float: right;
width: 100px;
height:20px;
margin-right: 10px;
border-radius: 5px;
background: -webkit-linear-gradient(left,rgb(0, 200, 0),rgb(30,144,255),rgb(255, 0, 0)) no-repeat;
}
后台渐变色方法 step为分多少个颜色
//查看字符串是否在数组中(双色渐变)
public static List<String> getStepColorsByCondition(int[] beginColor, int[] endColor, int step) {
List<String> list = new ArrayList();
list.add(intAryToString(beginColor));
if(step > 1){
step = step - 1;
}else{
return list;
}
for (int i = 1; i <= step; i++) {
StringBuffer newColor = new StringBuffer();
for (int j = 0; j < beginColor.length; j++) {
int bca = beginColor[j];
int eca = endColor[j];
//这个就是算法,RGB三色都按同样的算法
int newnum = bca + (eca - bca) / step*i;
newColor.append(newnum + ",");
}
list.add(newColor.deleteCharAt(newColor.length()-1).toString());
}
return list;
}
//查看字符串是否在数组中(三色渐变)
public static List<String> getStepColorsByCondition(int[] beginColor, int[] midColor, int[] endColor, int step) {
List<String> list = new ArrayList();
list.add(intAryToString(beginColor));
int num1;
int num2;
if(step%2 == 0){
num1 = num2 = step/2;
}else{
num1 = step/2+1;
num2 = step - num1;
}
if(num1 > 1){
num1 = num1 - 1;
}
for (int i = 1; i <= num1; i++) {
StringBuffer newColor = new StringBuffer();
for (int j = 0; j < beginColor.length; j++) {
int bca = beginColor[j];
int eca = midColor[j];
//这个就是算法,RGB三色都按同样的算法
int newnum = bca + (eca - bca) / num1*i;
newColor.append(newnum + ",");
}
list.add(newColor.deleteCharAt(newColor.length()-1).toString());
}
for (int i = 1; i <= num2; i++) {
StringBuffer newColor = new StringBuffer();
for (int j = 0; j < midColor.length; j++) {
int bca = midColor[j];
int eca = endColor[j];
//这个就是算法,RGB三色都按同样的算法
int newnum = bca + (eca - bca) / num2*i;
newColor.append(newnum + ",");
}
list.add(newColor.deleteCharAt(newColor.length()-1).toString());
}
return list;
}
public static void main(String[] args) {
int[] beginColor = {0,200,0};
int[] midColor = {0,0,255};
int[] endColor = {255,0,0};
List<String> stepColorsBy = getStepColorsByCondition(beginColor, endColor, 3);
System.out.println(JSON.toJSONString(stepColorsBy));
List<String> stepColorsByCondition = getStepColorsByCondition(beginColor, midColor, endColor, 12);
System.out.println(JSON.toJSONString(stepColorsByCondition));
}