使用Javascript从文件夹加载background.image序列

使用Javascript从文件夹加载background.image序列,javascript,css,Javascript,Css,我试图制作一个javascript源代码,将文件夹中的所有图像作为我的div的背景图像加载 <script type="text/javascript"> $(document).ready(function() { $('body').css('background-image', 'url(/web/images/001.png)'); }); </script> $(文档).ready(函数(){ $('body').css('b

我试图制作一个javascript源代码,将文件夹中的所有图像作为我的div的背景图像加载

<script type="text/javascript">
    $(document).ready(function() {
        $('body').css('background-image', 'url(/web/images/001.png)');
    });
</script>

$(文档).ready(函数(){
$('body').css('background-image','url(/web/images/001.png)');
});
如何将文件夹(web/images)中的所有图像(.png)作为div的背景图像加载

谢谢大家的支持,
M.

试试这样的方法:

$(document).ready(function() {
    var imgno=1;
    for(var imgno=1;imgno<50;imgno++){
       $('div').css({'width':'200px','height':'200px','background-image': 'url(/web/images/'+imgno+'.png)'});
    }

});
$(文档).ready(函数(){
var-imgno=1;

对于(var imgno=1;imgno请尝试以下操作:

$(document).ready(function() {
    var imgno=1;
    for(var imgno=1;imgno<50;imgno++){
       $('div').css({'width':'200px','height':'200px','background-image': 'url(/web/images/'+imgno+'.png)'});
    }

});
$(文档).ready(函数(){
var-imgno=1;

对于(var imgno=1;imgno请尝试以下操作:

$(document).ready(function() {
    var imgno=1;
    for(var imgno=1;imgno<50;imgno++){
       $('div').css({'width':'200px','height':'200px','background-image': 'url(/web/images/'+imgno+'.png)'});
    }

});
$(文档).ready(函数(){
var-imgno=1;

对于(var imgno=1;imgno请尝试以下操作:

$(document).ready(function() {
    var imgno=1;
    for(var imgno=1;imgno<50;imgno++){
       $('div').css({'width':'200px','height':'200px','background-image': 'url(/web/images/'+imgno+'.png)'});
    }

});
$(文档).ready(函数(){
var-imgno=1;

对于(var imgno=1;imgno引用此链接,您可以使用jquery setTimeout()函数在特定时间后更改背景。

引用此链接,您可以使用jquery setTimeout()函数在特定时间后更改背景。

引用此链接,您可以使用jquery setTimeout()函数用于在特定时间后更改背景。

请参考此链接,您可以使用jquery setTimeout()函数用于在特定时间后更改背景。

如果您希望使用间隔更改背景,请尝试此操作

$(document).ready(function() {
    // Function to add leading zeroes
    function pad(num, size) {
        var s = num + "";
        while (s.length < size) s = "0" + s;
        return s;
    }

    // Variable to store the current image index
    var currentIdx = 1; 
    var max = 200; // Qtd of images in the folder

    setInterval(function() {
        // Reset the index when overflow
        if(currentIdx > max) currentIdx = 1;
        // Change the background
        $('body').css('background-image', 'url(/web/images/' + pad(currentIdx,4) + '.png)');
        currentIdx ++;
    }, 5000); // 5000ms == 5 seconds
});
$(文档).ready(函数(){
//函数添加前导零
功能板(数量、大小){
var s=num+“”;
而(s.lengthmax)currentIdx=1;
//改变背景
$('body').css('background-image','url(/web/images/'+pad(currentIdx,4)+'.png)');
currentIdx++;
},5000);//5000ms==5秒
});

这里有一个

如果你想用一个间隔来改变背景,你应该试试这个

$(document).ready(function() {
    // Function to add leading zeroes
    function pad(num, size) {
        var s = num + "";
        while (s.length < size) s = "0" + s;
        return s;
    }

    // Variable to store the current image index
    var currentIdx = 1; 
    var max = 200; // Qtd of images in the folder

    setInterval(function() {
        // Reset the index when overflow
        if(currentIdx > max) currentIdx = 1;
        // Change the background
        $('body').css('background-image', 'url(/web/images/' + pad(currentIdx,4) + '.png)');
        currentIdx ++;
    }, 5000); // 5000ms == 5 seconds
});
$(文档).ready(函数(){
//函数添加前导零
功能板(数量、大小){
var s=num+“”;
而(s.lengthmax)currentIdx=1;
//改变背景
$('body').css('background-image','url(/web/images/'+pad(currentIdx,4)+'.png)');
currentIdx++;
},5000);//5000ms==5秒
});

这里有一个

如果你想用一个间隔来改变背景,你应该试试这个

$(document).ready(function() {
    // Function to add leading zeroes
    function pad(num, size) {
        var s = num + "";
        while (s.length < size) s = "0" + s;
        return s;
    }

    // Variable to store the current image index
    var currentIdx = 1; 
    var max = 200; // Qtd of images in the folder

    setInterval(function() {
        // Reset the index when overflow
        if(currentIdx > max) currentIdx = 1;
        // Change the background
        $('body').css('background-image', 'url(/web/images/' + pad(currentIdx,4) + '.png)');
        currentIdx ++;
    }, 5000); // 5000ms == 5 seconds
});
$(文档).ready(函数(){
//函数添加前导零
功能板(数量、大小){
var s=num+“”;
而(s.lengthmax)currentIdx=1;
//改变背景
$('body').css('background-image','url(/web/images/'+pad(currentIdx,4)+'.png)');
currentIdx++;
},5000);//5000ms==5秒
});

这里有一个

如果你想用一个间隔来改变背景,你应该试试这个

$(document).ready(function() {
    // Function to add leading zeroes
    function pad(num, size) {
        var s = num + "";
        while (s.length < size) s = "0" + s;
        return s;
    }

    // Variable to store the current image index
    var currentIdx = 1; 
    var max = 200; // Qtd of images in the folder

    setInterval(function() {
        // Reset the index when overflow
        if(currentIdx > max) currentIdx = 1;
        // Change the background
        $('body').css('background-image', 'url(/web/images/' + pad(currentIdx,4) + '.png)');
        currentIdx ++;
    }, 5000); // 5000ms == 5 seconds
});
$(文档).ready(函数(){
//函数添加前导零
功能板(数量、大小){
var s=num+“”;
而(s.lengthmax)currentIdx=1;
//改变背景
$('body').css('background-image','url(/web/images/'+pad(currentIdx,4)+'.png)');
currentIdx++;
},5000);//5000ms==5秒
});


这是一个

文件中是否有要加载的模式?是否按顺序加载?例如:001.png、002.png、003.png?是否要同时使用所有图像,还是要在它们之间设置间隔?如果添加/(斜杠)在路径开始时,浏览器将在example.com/web/images/001.pngSo中搜索文件,您的背景将从一个图像更改为另一个图像。我说的对吗?@nanndoj yes是sequenceyes@shridhar corrective您要加载的文件中是否有任何模式?是否按顺序?例如:001.png,002.png,003.png?是否要同时使用所有图像或者你想在它们之间有一个间隔吗?如果你加/(斜杠)在路径开始时,浏览器将在example.com/web/images/001.pngSo中搜索文件,您的背景将从一个图像更改为另一个图像。我说的对吗?@nanndoj yes是sequenceyes@shridhar corrective您要加载的文件中是否有任何模式?是否按顺序?例如:001.png,002.png,003.png?是否要同时使用所有图像或者你想在它们之间有一个间隔吗?如果你加/(斜杠)在路径开始时,浏览器将在example.com/web/images/001.pngSo中搜索文件,您的背景将从一个图像更改为另一个图像。我说的对吗?@nanndoj yes是sequenceyes@shridhar corrective您要加载的文件中是否有任何模式?是否按顺序?例如:001.png,002.png,003.png?是否要同时使用所有图像或者你想在它们之间有一个间隔?如果你在路径开始处添加/(斜线),浏览器将在example.com/web/images/001.pngSo中搜索文件,那么你的背景将从一个图像更改为另一个图像。我说的对吗?@nanndoj yes是sequenceyes@shridhar correchi,我对你的源代码有问题,我的图像是从0001.png到02的