我有一个运行良好的幻灯片。我只想一次显示多个幻灯片。如果您可以帮助我,那就太好了。
我听说过maxSlides属性,但是在这种情况下我不知道如何实现。
如果您有任何想法,请通知我。谢谢
我的代码如下:
<!DOCTYPE html>
<html>
<head>
<!-- Slideshow -->
<style>
.slide-container{
display: flex;
}
.slide {
width: 100%;
background-color: rgba(0, 0, 0, 0.25);
display:none;
}
.active {
display: inline;
}
/* Next & previous buttons */
.prev, .next {
cursor: pointer;
position: absolute;
top: 0%;
width: auto;
padding: 16px;
margin: 0 0 !important;
color: white;
font-weight: bold;
font-size: 30px;
transition: 0.6s ease;
border-radius: 0 3px 3px 0;
user-select: none;
background:transparent;
border: none;
}
/* Position the "next button" to the right */
.next {
right: 0;
border-radius: 3px 0 0 3px;
}
.prev {
left: 0;
border-radius: 3px 0 0 3px;
/* On hover, add a black background color with a little bit see-through */
.prev:hover, .next:hover {
background-color: rgba(0,0,0,0.8);
}
/* On smaller screens, decrease text size */
@media only screen and (max-width: 300px) {
.text {font-size: 11px}
}
</style>
<script>let slideIndex = 0;
const slideTime = 5000;
let slideInterval = setInterval(() => changeSlide(true), slideTime);
function jumpSlide(forward) {
clearInterval(slideInterval);
changeSlide(forward)
slideInterval = setInterval(() => changeSlide(true), slideTime);
}
function changeSlide(forward) {
const slides = document.getElementsByClassName('slide');
slides[slideIndex].classList.remove('active');
if (forward) {
if (slideIndex + 1 > slides.length - 1) {
slides[0].classList.add('active');
slideIndex = 0;
} else {
slides[slideIndex + 1].classList.add('active');
slideIndex ++;
}
} else {
if (slideIndex - 1 < 0) {
slides[slides.length - 1].classList.add('active');
slideIndex = slides.length - 1;
} else {
slides[slideIndex - 1].classList.add('active');
slideIndex --;
}
}
}</script>
</head>
<body>
<!-- Slideshow -->
<div class='slide-container' style="width:100%;">
<div class='slide active'>
<img src="https://images.pexels.com/photos/248797/pexels-photo-248797.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500" style="width:100%">
<div class="text" style="background-color: white">Caption Text 1</div>
</div>
<div class='slide'>
<img src="background-2.gif" style="width:100%">
<div class="text" style="background-color: white">Caption Text 2</div>
</div>
<div class='slide'>
<img src="background-1.gif" style="width:100%">
<div class="text" style="background-color: white">Caption Text 3</div>
</div>
<div class='slide'>
<img src="background-3.gif" style="width:100%">
<div class="text" style="background-color: white">Caption Text 4</div>
</div>
<button class="prev" onclick='jumpSlide(false)'>❮</button>
<button class="next" onclick='jumpSlide(true)'>❯</button>
</div>
</body>
</html>