In the user interface I developed, users have the ability to specify the number of floors in their building. Each menu item in the system corresponds to a floor. While this setup is functional, I am looking to give each menu item a unique background color and border color.
I initially used Math.random to generate colors, which was successful. However, every time the page is reloaded or navigated to another page, the colors change. My goal is to generate random colors once based on the number of floors and keep those colors consistent for subsequent visits.
Therefore, I am seeking assistance in implementing a JavaScript (or jQuery) solution that will generate colors one time, depending on the number of floors, and maintain those colors throughout.
while(countFloors>=1) {
var color ='#'+Math.random().toString(16).substr(2,6);
menu_container.innerHTML += "<li style=\"width: " + width + ";background-color:" + color + ";\" class=\"menu-item "+((floor == floorNumber) ? 'active' : '')+"\" id=\"floor-" + floorNumber + "\"><a href=\"/floor.html?floor=" + floorNumber + "\">Floor " + floorNumber +"</a></li>";
floorNumber++;
countFloors--;
}
This code currently includes functionality for random colors.
If anyone understands my objective and can provide guidance, it would be greatly appreciated.