Created
February 10, 2018 01:42
-
-
Save elmontoya7/718d2f0af9a53f291d4fea245051a76e to your computer and use it in GitHub Desktop.
Returns a contrasting color (black or white) depending on the background color. This is a functions used in Vue.js.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
getContrastFontColor () { | |
if(this.colorSelected.length == 7) { | |
let r = parseInt(this.colorSelected.substr(1,2),16); | |
let g = parseInt(this.colorSelected.substr(3,2),16); | |
let b = parseInt(this.colorSelected.substr(5,2),16); | |
r *= 0.299; | |
g *= 0.587; | |
b *= 0.114; | |
if((r + g + b) > 186) | |
return '#000000'; | |
else | |
return '#ffffff'; | |
} else { | |
return '#000000'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment