我目前有一个‘功能’的JS幻灯片/轮播,但我有一个问题,我有一个非常宽的幻灯片容器,它一次只能显示一个缩略图。
我想创建一组8个默认图像,显示在一次。如果你点击箭头,我希望它能再显示8张图片。除此之外,我希望它能告诉您您正在查看的图像。(例如:显示图像1到8)
这个用红色圈出的区域是我的整个幻灯片容器

但是你可以看到它只显示了一个图像和一个箭头。
我如何才能一次显示更多的图像,并根据需要继续?
<div class="w3-content w3-display-container">
<?php foreach ($imageResult as $im): ?>
<?php if($im['type'] == 'content'){?>
<img class="mySlides" src="<?php echo $im['url']; ?>" style="max-width:200px; max-height:200px;">
<?php } ?>
<?php endforeach?>
<button class="w3-button w3-black w3-display-left" onclick="plusDivs(-1)">❮</button>
<button class="w3-button w3-black w3-display-right" onclick="plusDivs(1)">❯</button>
</div>
<script>
var slideIndex = 1;
showDivs(slideIndex);
function plusDivs(n) {
showDivs(slideIndex += n);
}
function showDivs(n) {
var i;
var x = document.getElementsByClassName("mySlides");
if (n > x.length) {slideIndex = 1}
if (n < 1) {slideIndex = x.length}
for (i = 0; i < x.length; i++) {
x[i].style.display = "none";
}
x[slideIndex-1].style.display = "block";
}
</script>发布于 2019-01-14 14:58:54
也许可以试试这样的东西:
<script>
var slideIndex = 1; // This may skip the first image... maybe change to 0?
showDivs(slideIndex);
function plusDivs(n) {
showDivs(slideIndex += n);
}
function showDivs(n) {
var x = document.getElementsByClassName("mySlides");
if (n > x.length) {slideIndex = 1}
if (n < 1) {slideIndex = x.length}
// Assuming we can show the next 8 images...
var maxCount = slideIndex + 8;
// However, there may not be 8 more images...
if(slideIndex + 8 > x.length){
maxCount = slideIndex + (x.length - slideIndex);
}
// Hide all images...
x.style.display = "none";
// Show the next 8 or so images...
for (i = slideIndex; i <= maxCount; i++) {
x[i].style.display = "block";
}
}
</script>https://stackoverflow.com/questions/54175597
复制相似问题