我正在尝试制作幻灯片,但是当幻灯片移至下一张(或上一张)图像时,背景上没有任何内容。

我希望您将看到的图像出现在您所看到的图像的后面,例如当您洗牌时。

另外,当您单击向右或向左箭头以匹配其运动时,我希望具有不同的动画。

这是我现在正在使用的代码:

Code



<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.7.2/animate.min.css">
<style>
.mySlides {display: none}
img {vertical-align: middle;}

/* Slideshow container */
.slideshow-container {
  overflow: hidden;
  max-width: 300px;
  position: relative;
  margin: auto;
}

/* Next & previous buttons */
.prev, .next {
  cursor: pointer;
  position: absolute;
  top: 50%;
  width: auto;
  padding: 16px;
  margin-top: -22px;
  color: white;
  font-weight: bold;
  font-size: 18px;
  transition: 0.6s ease;
  border-radius: 0 3px 3px 0;
  user-select: none;
}

/* Position the "next button" to the right */
.next {
  right: 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);
}

</style>
</head>
<body>

<div class="slideshow-container">

 <div class="mySlides animated slideInLeft">
  <img src="https://pruebas20.webcindario.com/img_snow_wide.jpg" style="width:100%">
 </div>

 <div class="mySlides animated slideInRight">
  <img src="https://pruebas20.webcindario.com/img_nature_wide.jpg" style="width:100%">
 </div>

 <div class="mySlides slideInRight">
  <img src="https://pruebas20.webcindario.com/img_mountains_wide.jpg" style="width:100%">
 </div>

 <a class="prev" onclick="plusSlides(-1)">&#10094;</a>
 <a class="next" onclick="plusSlides(1)">&#10095;</a>

</div>

<script>
var slideIndex = 1;
showSlides(slideIndex);

function plusSlides(n) {
  showSlides(slideIndex += n);
}

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>

</body>
</html> 





谢谢!

最佳答案

问题是您正在使用JavaScript和CSS隐藏除当前幻灯片以外的所有内容。



for (i = 0; i < slides.length; i++) {
      slides[i].style.display = "none";
  }

.mySlides {display: none}





您将需要删除它,但是要更改幻灯片的z-index,以便当前幻灯片位于顶部,同时添加slideInRight / slideInLeft类。您还需要将幻灯片绝对定位在容器中,以便它们占据相同的位置。

09-25 20:06