I have made a website with one specific theme, is there a way to change the color of the background/text of the website when you refresh it? here is some code which can only change the background. How to make it so it will pick a theme with the text and background
CodePudding user response:
if you want change color of background or text, use DOM to access this style and edit:
var bgcolorArr = new Array("silver", "#BAF3C3", "#c3baf3", "red", "green", "blue")
document.body.style.backgroundColor = bgcolorArr[Math.floor(Math.random()*bgcolorArr.length)]
Update!! Use Array literals is shorter new Array():
var bgcolorArr = ["silver", "#BAF3C3", "#c3baf3", "red", "green", "blue"]
CodePudding user response:
You can use Math.random() on background color properties, ex: make the random number between 0-10, then make an array filled with hex values of colors you want. And then set the background or text color based on that Math_random().