js实现获取颜色渐变代码
Mar 02, 2018 pm 03:24 PMhtml中颜色可以使用rgb和hex方式来表示。在色彩中,色相、明度、纯度也都可以产生渐变效果,并会表现出具有丰富层次的美感。本文主要讲述两种颜色RGB数值的梯级渐变算法。
其中如如16进制颜色如#336600分别表示rgb模式中r的值为16进制33(即),g的值为16进制的66,和b为16进制的00,转换后用rgb完整表述为:rgb(51,102,0)。
其中使用16进制进行加减乘除不方便,尤其还使用了rgb的16进制颜色组合(#336600)。因此我们可以将16进制转换为rgb单个进行梯级运算在进行组合。
已知:RStart=50,REnd=200,RStart、REnd之间平均分成3份(Step=3),求每份的数值(StepN)分别是多少。
公式:Gradient = RStart+ (REnd-RStart) / Step * N (第N步的颜色rgb中R的值)
实现方法非常简单,只是需要将颜色从rgb到hex的互转。
实现代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
<br>
|
相关推荐:
The above is the detailed content of js实现获取颜色渐变代码. For more information, please follow other related articles on the PHP Chinese website!

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

What to do if the blue screen code 0x0000001 occurs

The computer frequently blue screens and the code is different every time

GE universal remote codes program on any device

What does the blue screen code 0x000000d1 represent?

Detailed explanation of the causes and solutions of 0x0000007f blue screen code

Tsinghua University and Zhipu AI open source GLM-4: launching a new revolution in natural language processing
