Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
基于时间更改背景图像(javascript)_Javascript_Html_Css - Fatal编程技术网

基于时间更改背景图像(javascript)

基于时间更改背景图像(javascript),javascript,html,css,Javascript,Html,Css,在下面的代码中,我根据计时器中剩余的秒数更改背景颜色。我试图找出是否有一种方法可以根据时间改变背景图像 我试图补充以下内容: var imgArray=['something.jpg','something2.jpg']; 函数changeColor(){ 如果(90秒){ document.body.style.background=imgArray[0]; } 否则,如果(30秒){ document.body.style.background=imgaray[1]; } 其他(秒=0){

在下面的代码中,我根据计时器中剩余的秒数更改背景颜色。我试图找出是否有一种方法可以根据时间改变背景图像

我试图补充以下内容:

var imgArray=['something.jpg','something2.jpg'];
函数changeColor(){
如果(90秒){
document.body.style.background=imgArray[0];
}
否则,如果(30秒){
document.body.style.background=imgaray[1];
}
其他(秒=0){
document.body.style.background=imgArray[0];
}

};您需要使用url(..)围绕该值设置背景

document.body.style.background = "url(" + imgArray[1] + ")";