混合2种以上颜色和javascript [英] mix more than 2 colors together with javascript

查看:74
本文介绍了混合2种以上颜色和javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试一起添加JS颜色.我在这个问题上坐了好几天了.问题是颜色在十六进制代码中.

I´m trying to add in JS colors together. I´m sitting on front of this problem for days now. The problem is the colors are in hex code.

现在,我想将所有颜色加在一起打印并以div或其他方式打印出来.

Now i´d like to add all the colors together to print and print it out in a div, or something.

您能告诉我演示如何做吗?

Could you show me demo plz how to do it ?

这是我的意思的照片:

十六进制代码是<input>类型.

The hex code is an <input> type.

推荐答案

根据评论,我不确定100%表示混合"是什么意思,但是假设您希望将它们组合起来,则可以这样做通过使用 xcolor 之类的插件.

As per the comments, I'm not 100% sure what you mean by "mix", but assuming you to want to combine them, you could do so by using a plugin such as xcolor.

例如$.xcolor.additive(color, color)计算两种颜色的加色混合.

e.g. $.xcolor.additive(color, color) calculates the additive color mix of two colors.

因此,您可以执行以下操作:

So, you could do something like:

var $inputs = $("input"); // You'll want to make this more specific
var color = "";

$inputs.each(function(){
  var curColor = this.value;
  if(color === ""){
    color = curColor;
  }

  color = $.xcolor.additive(color, curColor);
});

这是 小提琴

Here's a fiddle

这篇关于混合2种以上颜色和javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆