gpt4 book ai didi

javascript - 为什么我的 JS 代码在调用 JS 函数 showSlides(SLIDEINDEX) 时没有显示任何其他幻灯片;即使我更改了 SLIDEINDEX 的值?

转载 作者:行者123 更新时间:2023-11-30 14:28:45 25 4
gpt4 key购买 nike

我不知道我的 js 代码有什么问题,请检查下面并通过更改 SLIDEINDEX 的值帮助我显示其他特定幻灯片

    // initialize slideindex with 0 as you want to show the first slide first
var SLIDEINDEX = 3;

showSlides(SLIDEINDEX);

// creating function for showing slides
function showSlides(index){
// lets select all the slides and dots using querySelectorAll method
var slides = document.querySelectorAll(".slide");
var dots = document.querySelectorAll(".dots-navigation");
// if slide index value is greater than length of slides then jump to 1st slide
if (index >= slides.length) {SLIDEINDEX = 0;}
// if we want to jump at the last of the slide incase the user is at the first one
if (index < 0) {SLIDEINDEX = slides.length - 1;}

// before showing slides we must hide all the slides and remove active-dots class using for loop
for (var i = 0; i < slides.length; i++){
// hide slide elements
slides[i].style.display = "none";
// hide dots active-dot class
dots[i].classList.remove("active-dot");
}
// show the slide we want and set the dot class active-dot
slides[SLIDEINDEX].style.display = "block";
dots[SLIDEINDEX].classList.add("active-dot");

};

这是其他部分,如HTML和CSS代码,请点击链接HTML 代码链接:- https://pastebin.com/nUcqnXnj和 CSS 代码链接:- https://pastebin.com/T2CZPNeh

最佳答案

我认为 SLIDEINDEX var 未被使用。仅当它超出幻灯片限制时才设置它。

...
// if slide index value is greater than length of slides then jump to 1st slide
if (index >= slides.length) {SLIDEINDEX = 0;}
// if we want to jump at the last of the slide incase the user is at the first one
else if (index < 0) {SLIDEINDEX = slides.length - 1;}
// else set SLIDEINDEX with new index
else {SLIDEINDEX = index;}
...

关于javascript - 为什么我的 JS 代码在调用 JS 函数 showSlides(SLIDEINDEX) 时没有显示任何其他幻灯片;即使我更改了 SLIDEINDEX 的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51532827/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com