方法 1:
现在可以使用 CSS mix-blend-mode 来实现所需的效果。目前仅支持 Chrome。
访问 chrome://flags/ 和“启用实验性 Web 平台功能”查看效果。
http://jsfiddle.net/9AgDm/4/
<div style="width: 200px; height: 200px; background-color: #F00; position: absolute; top: 100px; left: 100px;"></div>
<div style="width: 200px; height: 200px; background-color: #0F0; position: absolute; top: 0; left: 0;"></div>
<div style="width: 200px; height: 200px; background-color: #F00; position: absolute; top: 100px; left: 100px; mix-blend-mode: screen;"></div>
方法 2:
也可以使用 background-blend-mode 在单个 HTML 元素上使用多个背景渐变来实现该效果。
在此处查看浏览器支持:
http://caniuse.com/css-backgroundblendmode
http://jsfiddle.net/9AgDm/5/
<div></div>
CSS:
div {
background-blend-mode: screen;
background:
linear-gradient(to right, #0F0, #0F0),
linear-gradient(to right, #F00, #F00);
background-position:
0 0,
100px 100px;
background-repeat: no-repeat;
background-size:
200px 200px,
200px 200px;
height: 300px;
width: 300px;
}
方法 3:
使用 SVG 的效果相同。适用于大多数浏览器。
测试于:
法郎 7+;铬 16+; IE 10+;歌剧 12+; Safari 5、6+(在 5.1 上失败)
http://jsfiddle.net/9AgDm/9/
<svg width="300" height="300">
<defs>
<filter id="additive">
<feFlood x="0" y="0" width="200" height="200" flood-color="#0F0" result="a"/>
<feFlood x="100" y="100" width="200" height="200" flood-color="#F00" result="b"/>
<feBlend in="a" in2="b" result="ab" mode="screen"/>
</filter>
</defs>
<rect filter="url(#additive)" width="100%" height="100%"/>
</svg>
方法 4:
除了 IE8 及以下版本,canvas 可以在大多数浏览器上运行。以下是一些可以实现加色的示例/库:
http://media.chikuyonok.ru/canvas-blending/
http://www.pixastic.com/lib/docs/actions/blend/
http://canvasquery.com/#blending