js判断background颜色明暗色调,以设置白/黑字体颜色

整理自:jscolor.js插件

 

this.styleElement.style.color = this.isLight() ? '#000' : '#FFF';

 

this.isLight = function () {

return (

0.213 * this.rgb[0] +

0.715 * this.rgb[1] +

0.072 * this.rgb[2] >

255 / 2

);

};

原文地址:https://www.cnblogs.com/helkbore/p/5355930.html