我的幻灯片不会滑到下一张幻灯片

时间:2019-10-10 12:58:42

标签: javascript html css

我有一个基本的幻灯片显示,它不会滑动到下一张幻灯片,并且我将其设置为每2秒滑动一次。我已经搜索了youtube,google甚至在此站点上,但是每种方法均无效。

var slideIndex = 0;
showSlides();

function showSlides() {
  var i;
  var slides = document.getElementsByClassName("mySlides");
  var dots = document.getElementsByClassName("dot");
  for (i = 0; i < slides.length; i++) {
    slides[i].style.display = "none";
  }
  slideIndex++;
  if (slideIndex > slides.length) {
    slideIndex = 1
  }
  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";
  setTimeout(showSlides, 2000); // Change image every 2 seconds
}
* {
  box-sizing: border-box;
}

body {
  font-family: Verdana, sans-serif;
}

.mySlides {
  display: none;
}

img {
  vertical-align: middle;
}


/* Slideshow container */

.slideshow-container {
  max-width: 1000px;
  position: relative;
  margin: auto;
}


/* Caption text */

.text {
  color: #f2f2f2;
  font-size: 15px;
  padding: 8px 12px;
  position: absolute;
  bottom: 8px;
  width: 100%;
  text-align: center;
}


/* Number text (1/3 etc) */

.numbertext {
  color: #f2f2f2;
  font-size: 12px;
  padding: 8px 12px;
  position: absolute;
  top: 0;
}


/* The dots/bullets/indicators */

.dot {
  height: 15px;
  width: 15px;
  margin: 0 2px;
  background-color: #bbb;
  border-radius: 50%;
  display: inline-block;
  transition: background-color 0.6s ease;
}

.active {
  background-color: #717171;
}


/* Fading animation */

.fade {
  -webkit-animation-name: fade;
  -webkit-animation-duration: 1.5s;
  animation-name: fade;
  animation-duration: 1.5s;
}

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

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


/* On smaller screens, decrease text size */

@media only screen and (max-width: 300px) {
  .text {
    font-size: 11px
  }
}
<div id="holder">
  <div class="row" id="one">
    <div class="slideshow-container">

      <div class="mySlides fade">
        <div class="numbertext">1 / 3</div>
        <img src="//images.australiazoo.com.au/azhome/steve_irwin_gala_dinner.jpg" style="width:100%">

        <div class="mySlides fade">
          <div class="numbertext">2 / 3</div>
          <img src="//images.australiazoo.com.au/azhome/petition_home_page.jpg" style="width:100%">
        </div>

        <div class="mySlides fade">
          <div class="numbertext">3 / 3</div>
          <img src="//images.australiazoo.com.au/azhome/ROBERT_IRWIN_WEBSITE_HP_BANNER.jpg" style="width:100%">
        </div>

      </div>

任何帮助将不胜感激,并在此先感谢。

P.S这些图像只是占位符。

1 个答案:

答案 0 :(得分:0)

工作fiddle

HTML 中存在一些错误,例如放错位置和缺少结尾的</div>标签以及脚本代码。在这种情况下,请尝试更多调试。

相关问题