This should fix this problem, (it is also more readable).
‘#’+(Math.random()*0xFFFFFF<<0).toString(16);
Ken
The formula is incorrect. here is a corrected version:
var x=Math.round(0xffffff * Math.random()).toString(16);
var y=(6-x.length);
var z=”000000″;
var z1 = z.substring(0,y);
var color= “#” + z1 + x;
This way if the length of the Hex number is too short, the appropriate number of zeros are added to the beginning and you don’t get any illegal values for color.
Sometimes script make wrong string, 5 chars only.
This should fix this problem, (it is also more readable).
‘#’+(Math.random()*0xFFFFFF<<0).toString(16);
The formula is incorrect. here is a corrected version:
var x=Math.round(0xffffff * Math.random()).toString(16);
var y=(6-x.length);
var z=”000000″;
var z1 = z.substring(0,y);
var color= “#” + z1 + x;
This way if the length of the Hex number is too short, the appropriate number of zeros are added to the beginning and you don’t get any illegal values for color.
Hi all sorry to be dense but how do I integrate this into CSS code as the example has done?
Many thanks,
Andrew.
DigWP
A book and blog co-authored by Jeff Starr and myself about the World's most popular publishing platform.
Quotes on Design
Design, like Art, can be an elusive word to define and an awfully fun thing to have opinions about.
HTML-Ipsum
One-click copy to clipboard access to Lorem Ipsum text that comes wrapped in a variety of HTML.
Bookshelf
Hey Chris, what books do you recommend? These, young fertile mind, these.