LoginSignup
29
27

More than 5 years have passed since last update.

背景色によって、字を白と黒どちらにするか判定

Posted at

====================================

参考
http://stackoverflow.com/questions/3942878/how-to-decide-font-color-in-white-or-black-depending-on-background-color

// RGBで対比させる色 黒/白
function colorOnRGB(rgb) {
    var red = rgb.r,
    green = rgb.g,
    blue = rgb.b;

    var color = 'black';
    if ((red * 0.299 + green * 0.587 + blue * 0.114) < 186) {
        color = 'white';
    }
    return color;
}
29
27
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
29
27