javascript幻灯片放映不循环(在4张图片之前和之后变为空白)

时间:2016-10-19 13:11:19

标签: javascript slideshow

首先,在编码方面,我是一个巨大的菜鸟。我花了很长时间试图让幻灯片显示工作,这次我真的很接近,但它并没有循环。

它在页面预览上工作正常,但它在实际页面上没有按照需要播放。你可以看到它here

我永远感激有人可以帮助我。这可能是个问题吗?



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}
  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";
}
&#13;
/* Slideshow container */
.slideshow-container {
  max-width: 1000px;
  position: relative;
  margin: auto;
}

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

/* Position the "next button" to the right */
.next {
  right: 0;
  border-radius: 3px 0 0 3px;
}

/* Caption text */
.text {
  font-family: calibri;
  letter-spacing:2px;
  font-weight: bold;
  color: #000000;
  font-size: 15px;
  padding: 8px 12px;
  position: absolute;
  bottom: -105px;
  width: 100%;
  text-align: center;
}

/* Fading animation */
.fade {
  -webkit-animation-name: fade;
  -webkit-animation-duration: 1s;
  animation-name: fade;
  animation-duration: 1s;
}

@-webkit-keyframes fade {
  from {opacity: .1} 
  to {opacity: 1}
}

@keyframes fade {
  from {opacity: .1} 
  to {opacity: 1}

}
&#13;
<div class="slideshow-container">
  <div class="mySlides fade">
    <img src="http://i.imgur.com/EO5AEjZ.png" style="width:100%">
    <div class="text">SKETCH</div>
  </div>

  <div class="mySlides fade">
    <img src="http://i.imgur.com/PUtdId3.png" style="width:100%">
    <div class="text">FLAT</div>
  </div>

  <div class="mySlides fade">
    <img src="http://i.imgur.com/xSAPW2s.png" style="width:100%">
    <div class="text">SHADED</div>
  </div>
  
  <div class="mySlides fade">
    <img src="http://i.imgur.com/WC2aJk4.png" style="width:100%">
    <div class="text">BACKGROUND</div>
  </div>

  <a class="prev" onclick="plusSlides(-1)"><img src="http://i.imgur.com/jm8JWDw.png"></a>
  <a class="next" onclick="plusSlides(1)"><img src="http://i.imgur.com/vJsaNCY.png"></a>
</div>
&#13;
&#13;
&#13;

0 个答案:

没有答案