如何找出渐变中的所有颜色?
可能的重复:
Javascript颜色渐变
我有颜色一(比如说黄色)和颜色二(蓝色) - 它们组成渐变。
基于 0 到 100 的值(0 表示黄色,100 表示蓝色),我想表示颜色一和颜色二的混合。
我正在尝试在移动浏览器(特别是 safari)中执行此操作。
有没有办法在 JavaScript 中做到这一点?
Possible Duplicate:
Javascript color gradient
I have color one (let's say yellow) and color two (blue) - they make up a gradient.
Based on a value of 0 to 100, (0 being yellow and 100 being blue), I'd like to represent a mixture of color one and two.
I am trying to do this in a mobile browser (safari specifically).
Is there a way to do this in javascript?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想要创建一种颜色,该颜色在两种其他颜色之间具有一定的百分比 (0-100),您可以使用以下 javascript 来实现:
此函数假设渐变是通过每个 r、g 之间的线性插值来实现的和两个端点颜色的 b 通道值,使得 50% 梯度值是每个 r、g、b 值的中点(所呈现的两种颜色之间的中间)。一次也可以制作不同类型的渐变(使用不同的插值函数)。
要将此结果分配给背景,您可以使用我添加到返回结果中的 CSS 颜色值,如下所示:
If what you're trying to do is to create a color that is some percentage (0-100) between two other colors, you can do that with this javascript:
This function assumes the gradient is made with linear interpolation between each r, g and b channel value of the two endpoint colors such that the 50% gradient value is the midpoint of each r,g,b value (halfway between the two colors presented). Once could make different types of gradients too (with different interpolation functions).
To assign this result to a background, you use the CSS color value I've added to the return result like this: