How to increment / decrement hex color values with javascript / jQuery

前端 未结 3 1304
说谎
说谎 2021-02-06 07:33

Is it possible to increment or decrement hex color values on a step-by-step basis in jQuery / javascript?

What I would like to do is something like this:

Adapt

3条回答
  •  自闭症患者
    2021-02-06 08:16

    Use setInterval to remove exception(stack overflow). jsfiddle

     var start = 0x000000,
        end = 0xFFFFFF, temp;
        var intervalId = setInterval(function(){
           if(start== end){clearInterval(intervalId )};
           temp = (start).toString(16);                  
                 if(temp.length < 8){
    
                     temp = "0000000".substring(0, 8-temp.length)+temp; 
                 } 
                           start++;
                console.log(temp ); 
         }, 10);   
    

提交回复
热议问题