Dynamically change color to lighter or darker by percentage CSS (Javascript)

后端 未结 24 1806
-上瘾入骨i
-上瘾入骨i 2020-11-28 01:12

We have a big application on the site and we have a few links which are, let\'s say blue color like the blue links on this site. Now I want to make some other links, but wit

24条回答
  •  旧时难觅i
    2020-11-28 01:39

    You could use a little javascript to calculate the darker and lighter color using the rgb().

    Fiddle : Not really nice, but it is just for illustration.

    What it essentially does is sets a color and selects 20 colors with the same amount (compared to one another) of rgb only with 10 apart.

    for (var i=-10; i < $('.row:eq(0) .block').length/2 ; i++) {
     var r = 91;
     var g = 192;
     var b = 222;
     $('.row:eq(1) .block:eq('+(i+10)+')').css('background' , color(r+(i*10),g+(i*10),b+   (i*10))      );
    };
    

提交回复
热议问题