Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. function AccessibleColor(el) {
  2. var backgroundRGB = el.css("backgroundColor");
  3. backgroundRGB = backgroundRGB.substring(backgroundRGB.length - 1, 4).replace(/\s/g, "").split(",");
  4.  
  5. var sum = Math.round((
  6. (parseInt(backgroundRGB[0]) * 299) +
  7. (parseInt(backgroundRGB[1]) * 587) +
  8. (parseInt(backgroundRGB[2]) * 114)) / 1000);
  9.  
  10. if (sum > 128) {
  11. el.style.color = "black";
  12. } else {
  13. el.style.color = "white";
  14. }
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement