javascript实现随时变化着的背景颜色
很简单的一段背景颜色时刻发生变化的代码
<!doctypehtml>
<htmllang="en">
<head>
<metacharset="UTF-8">
<title>Document</title>
<style>
#dv{width:100px;height:100px;}
</style>
</head>
<script>
window.onload=function(){
varoDv=document.getElementById('dv');
oDv.style.backgroundColor='red'
setInterval(function(){
vararrRandNumber=[
getRandomNumber(0,255),
getRandomNumber(0,255),
getRandomNumber(0,255)
];
oDv.style.backgroundColor='rgb('+arrRandNumber[0]+','+arrRandNumber[1]+','+arrRandNumber[2]+')'
functiongetRandomNumber(rMin,rMax){
varcha=rMax-rMin;
varrand=Math.random();
//return(rMin+Math.round(cha*rand))
}
},500)
//alert(getRandomNumber(0,255))
};
</script>
<body>
<divid="dv"></div>
</body>
</html>
以上所述就是本文给大家分享的全部内容了,希望能够对大家学习使用javascript有所帮助。
热门推荐
3 祝福语简短的微信
10 幼儿祝福语大全简短贺卡
11 感谢教官文案祝福语简短
12 鼠年同事祝福语简短创意
13 元旦祝福语 简短独特群发
14 妈咪跟我生日祝福语简短
15 给儿子新婚祝福语简短
16 伴娘祝福语长文案简短
17 恭喜高考完祝福语简短
18 生日祝福语送老公简短