what mean 'always changing'? well, example, windows 8 installing screen, see text @ middle says:'you can new apps store', , background changing red orange yellow green cyan blue purple red. mean, how do html background javascript?
the simplest, effective , shortest amount of code using css , js
css:
#mydiv { transition: background-color 2s; }
then can set colors in array , call them when need, or ever often, or use below function generate random colors.
js:
function randomcolor() { return '#'+ ('000000' + (math.random()*0xffffff<<0).tostring(16)).slice(-6) }
here fiddle generates random colors every 2 seconds
https://jsfiddle.net/mlyyxmr1/2/
function randomcolor() { return '#'+ ('000000' + (math.random()*0xffffff<<0).tostring(16)).slice(-6) } function setcolor(){ document.getelementbyid('mydiv').style.backgroundcolor = randomcolor(); settimeout(setcolor, 2000); } setcolor();
#mydiv { background-color: red; transition: background-color 2s; }
<div id='mydiv' style='width:200px;height:200px;'> </div>
Comments
Post a Comment