我正在努力解决一页上有多个滑块的问题。我已经修复了一些随机问题,例如在 stackoverflow 上搜索时图像未显示或消失,但对于这个问题,我一直在寻找类似问题的答案,但我不太明白他们是如何修复它的,因为只发布了固定代码。
然而,据我了解,每个滑块 div 应该有不同的 scripID,但我无法解决它。
这是我的代码:
HTML:
<div class="card" class="col-md-3">
<!-- Slideshow container -->
<div class="slideshow-container">
<!-- Full-width images with number and caption text -->
<div class="mySlides fade">
<img src="/images/1.jpg" style="width:100%">
</div>
<div class="mySlides fade">
<img src="/images/2.jpg" style="width:100%">
</div>
<div class="mySlides fade">
<img src="/images/3.jpg" style="width:100%">
</div>
<!-- Next and previous buttons -->
<a class="prev" onclick="plusSlides(-1)">❮</a>
<a class="next" onclick="plusSlides(1)">❯</a>
</div>
<br>
<!-- The dots/circles -->
<div style="text-align:center">
<span class="dot" onclick="currentSlide(1)"></span>
<span class="dot" onclick="currentSlide(2)"></span>
<span class="dot" onclick="currentSlide(3)"></span>
</div>
<h2>Header </h2>
<hr>
<p class="hinfo">headerinfo</p>
<p>Text info on the card</p>
<p>Grey & Walnut colors<br>W:120 • D:120 • H:77</p>
</div>
脚本:
var slideIndex = 1;
showSlides(slideIndex);
// Next/previous controls
function plusSlides(n) {
showSlides(slideIndex += n);
}
// Thumbnail image controls
function currentSlide(n) {
showSlides(slideIndex = n);
}
function showSlides(n) {
var i;
var slides = document.getElementsByClassName("mySlides");
var dots = document.getElementsByClassName("dot");
if (n > slides.length) {slideIndex = 1}
if (n < 1) {slideIndex = slides.length}
for (i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
}
for (i = 0; i < dots.length; i++) {
dots[i].className = dots[i].className.replace(" active", "");
}
slides[slideIndex-1].style.display = "block";
dots[slideIndex-1].className += " active";
}
</script>
四季花海
相关分类