以下是我用来定期运行函数的函数。我使用该功能来改变身体的背景。但由于某种原因它没有被解雇。请帮我处理这段代码。
setInterval(uiImageChanger(),1);
function uiImageChanger(){
var currentTime = new Date().getHours();
var images = ['image1.jpg','image2.jpg'];
if( currentTime > 00 && currentTime <= 12){
$('body').css('background-image', "url(" + randomImagePicker(images ,'breakfast') + ")");
}else if( currentTime > 12 && currentTime <= 16){
$('body').css('background-image', "url(" + randomImagePicker(images ,'lunch') + ")");
}else if( currentTime > 16 && currentTime <= 00){
$('body').css('background-image', "url(" + randomImagePicker(images ,'dinner') + ")");
}
}
function randomImagePicker(imgArray,time){
if(time == 'breakfast'){
return "../images/main_image/breakfast/" + imgArray[Math.floor(Math.random() * imgArray.length)];
}else if(time == 'lunch'){
return "../images/main_image/lunch/" + imgArray[Math.floor(Math.random() * imgArray.length)];
}else if(time == 'dinner'){
return "../images/main_image/dinner/" + imgArray[Math.floor(Math.random() * imgArray.length)];
}
}
谢谢你。