如何在JavaScript中生成一个颜色较浅的随机十六进制代码? [英] How do I generate a random hex code that of a lighter color in javascript?
问题描述
我为背景使用随机颜色,但由于文本是黑色的,因此当生成真正的深色时,文本将无法看到。如何在生成十六进制代码时排除这些暗色?
我只能弄清楚如何得到它:
Math.floor(Math.random()* 16777215).toString(16)
不排除黑暗的颜色。有人可以帮我吗?
预先感谢您!
我要做的是为每个(RGB)(即 000000
到 FFFFFF
)生成一个从00到FF的数字。 。我也会确保G值大约高于33。
I am using a random color for the background, but since the text is black, when really dark colors are generated, the text can't be seen. How do I exclude these dark colors when generating the hexadecimal code?
I could only figure out how to get this:
Math.floor(Math.random()*16777215).toString(16)
But this does not exclude dark colors. Could someone please help me?
Thank you in advance!
What I would do is generate a number from 00 to FF for each (RGB) (ie 000000
to FFFFFF
). I would also make sure the G value is approximately higher than 33.
这篇关于如何在JavaScript中生成一个颜色较浅的随机十六进制代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!