html自动更改背景颜色,javascript实现随时变化着的背景颜色
很简单的一段背景颜色时刻发生变化的代码Document#dv {width: 100px;height: 100px;}window.onload=function(){var oDv = document.getElementById('dv');oDv.style.backgroundColor='red'setInterval(function(){var arrRandNumber = [
很简单的一段背景颜色时刻发生变化的代码
Document#dv {width: 100px;height: 100px;}
window.onload=function(){
var oDv = document.getElementById('dv');
oDv.style.backgroundColor='red'
setInterval(function(){
var arrRandNumber = [
getRandomNumber(0,255),
getRandomNumber(0,255),
getRandomNumber(0,255)
];
oDv.style.backgroundColor='rgb('+arrRandNumber[0]+','+arrRandNumber[1]+','+arrRandNumber[2]+')'
function getRandomNumber(rMin,rMax){
var cha = rMax-rMin;
var rand = Math.random();
//return (rMin+Math.round(cha*rand))
}
},500)
//alert(getRandomNumber(0,255))
};
以上所述就是本文给大家分享的全部内容了,希望能够对大家学习使用javascript有所帮助。
更多推荐
所有评论(0)