简单的画廊下一个按钮背景图像

时间:2022-04-03 19:41:12

I am trying to create a very simple gallery with background images on the body tag and previous /next buttons. Therefor I created an array containing the images and calling the actual index. Unfotrunately I can not call the first image bg_01.Jpg to start with and my prev/next buttons stop at the third image? I also created a fiddle here: Any help would be appreciated.

我正在尝试创建一个非常简单的图库,其中包含正文标记和上一个/下一个按钮的背景图像。因此,我创建了一个包含图像并调用实际索引的数组。不幸的是,我不能打电话给第一张图片bg_01.Jpg开始,我的上一个/下一个按钮停在第三张图片上?我也在这里创造了一个小提琴:任何帮助将不胜感激。

var Images = ['bg_01, bg_02', 'bg_03', 'bg_04', 'bg_05', 'bg_06', 'bg_07', 'bg_08', 'bg_09', 'bg_10', 'bg_11', 'bg_12'];
var ImgLength = Images.length;
$("body").css("background-image", "url(../img/" + Images[0] + ".jpg)");
$('#panel .left').click(function () {
    if (ImgLength > 0) {
        ImgLength = ImgLength - 1;
    } else {
        ImgLength = 0;
    }
    $("body").css("background-image", "url(../img/" + Images[ImgLength] + ".jpg)");
    return false;
});

$('#panel .right').click(function () {
    if (ImgLength < Images.length - 1) {
        ImgLength = ImgLength + 1;
    } else {
        ImgLength = 0;
    }
    $("body").css("background-image", "url(../img/" + Images[ImgLength] + ".jpg)");
    return false;
});

1 个解决方案

#1


2  

Your array has a mistake:

你的阵列有一个错误:

['bg_01, bg_02',...

you've missed to close 'bg_01' and open 'bg_02' strings

你错过了关闭'bg_01'并打开'bg_02'字符串

so your array's first element is 'bg_01, bg_02'

所以你的数组的第一个元素是'bg_01,bg_02'

#1


2  

Your array has a mistake:

你的阵列有一个错误:

['bg_01, bg_02',...

you've missed to close 'bg_01' and open 'bg_02' strings

你错过了关闭'bg_01'并打开'bg_02'字符串

so your array's first element is 'bg_01, bg_02'

所以你的数组的第一个元素是'bg_01,bg_02'