Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.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 使用jquery自动更改背景图像_Javascript_Jquery_Html_Css - Fatal编程技术网

Javascript 使用jquery自动更改背景图像

Javascript 使用jquery自动更改背景图像,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我正在使用以下jquery代码: (function() { var curImgId = 0; var numberOfImages = 42; // Change this to the number of background images window.setInterval(function() { $('body').css('background-image','url(/background' + curImgId + '.jpg)');

我正在使用以下jquery代码:

 (function() {
    var curImgId = 0;
    var numberOfImages = 42; // Change this to the number of background images
    window.setInterval(function() {
        $('body').css('background-image','url(/background' + curImgId + '.jpg)');
        curImgId = (curImgId + 1) % numberOfImages;
    }, 15 * 1000);
})();
这个CSS:

.body-1{
    background: url("../background/Living Room.jpg") no-repeat center center fixed;
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: cover;


    width: 100%;
    height:100%;

}
在我的背景文件夹中,我有两个不同名称的图像。当我加载页面时,CSS代码中引用的图像会被加载,但是当使用jquery加载另一个页面时,我会一直得到白色背景


有人能帮我解决这件事吗?

在word
background
之后缺少
/
,图像文件名中有空格。dey实际上是不允许的,它将根据浏览器/doctype/服务器的不同而中断。在css中,您有
。/background/客厅.jpg
,而在jQuery中,您没有在路径前提供两个点。这两个点用于在路径树的一个层次上上升。在
jQuery:url(../background/'+curImgId+'.jpg)
中尝试这样写。正如Vivek所说,CSS路径中有一个空格。