我想在html页面上进行幻灯片放映,并在W3网站上找到html / javascript代码并将其复制。但这行不通。我所得到的只是列表中显示的3张图像。我一直在看这里有关该主题的一些答案,但仍然无法找出问题所在。我认为代码已经完成,可以使用了。所以请帮忙。
代码如下:

JavaScript
    
    //自动幻灯片放映-每3秒钟更改一次图片
    var slideIndex = 0;
    showSlides();

function showSlides() {
    var i;
    var slides = document.getElementsByClassName("mySlides");
    for (i = 0; i < slides.length; i++) {
        slides[i].style.display = "none";
    }
    slideIndex++;
    if (slideIndex> slides.length) {slideIndex = 1}
    slides[slideIndex-1].style.display = "block";
    setTimeout(showSlides, 3000);
}
the html
<!-- Slide Show section showing 3 img every 3 sec-->
    <div class="slideshow-container">
    <div class="mySlides fade">
    <img class="mySlides" src="../images/Icons/sa.png" alt="a"
    style="width:100%">
    </div>
    <div class="mySlides fade">
    <img class="mySlides" src="../images/images/b.jpg" alt="b"
    style="width:100%" >
    </div>
    <div class="mySlides fade">
    <img class="mySlides" src="../images/images
     /c.jpg" alt="c"
    style="width:100%">
    </div>

最佳答案

您需要CSS,样式是使其发挥作用的重要部分。这是完整代码的链接:

http://www.w3schools.com/howto/tryit.asp?filename=tryhow_js_slideshow_auto

<style>
* {box-sizing:border-box}
body {font-family: Verdana,sans-serif;}

/* 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: 13px;
  width: 13px;
  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}
}
</style>

09-28 08:06