使用jquery自动更改背景图像

时间:2014-08-17 08:21:38

标签: 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)');
        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%;

}

在我的后台文件夹中,我有2个不同名字的图像。当我加载页面时,CSS代码中引用的图像被加载,但是当另一个应该使用jquery加载时,我会继续获得白色背景。

有人可以帮我解决这个问题吗?

0 个答案:

没有答案