Automatically change text color to assure readability

前端 未结 8 2052
生来不讨喜
生来不讨喜 2020-12-08 00:42

Users can set the background-color of a button through a textbox that accept RGB hexadecimal notation: ff00ff, ccaa22, etc. So I need to set the te

8条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-08 01:44

    I linked another Question to this topic in the comments.
    JS function to calculate complementary colour?

    As Tejasva said you need to need to convert RGB to HSL, complement the Hue and convert it back.

    I implemented the linked answer as a sample. Please upvote the original poster if this was helpful for you, because they provided the solution in fact.

    Sample
    http://jsfiddle.net/pLZ89/2/

提交回复
热议问题