图片幻灯片。如何制作幻灯片效果?

时间:2018-03-01 01:35:18

标签: javascript html css image slideshow

我无法尝试在幻灯片中制作图像" slide"。如果您知道我的意思,当前代码只会更改图像,但我想要一个幻灯片效果。我怎么能做到这一点?



var myIndex = 0;
carousel();

function carousel() {
  var i;
  var x = document.getElementsByClassName("mySlides");
  for (i = 0; i < x.length; i++) {
    x[i].style.display = "none";
  }
  myIndex++;
  if (myIndex > x.length) {
    myIndex = 1
  }
  x[myIndex - 1].style.display = "block";
  setTimeout(carousel, 3000); // Change image every 2 seconds
}
&#13;
.mySlides {
  display: none;
}
&#13;
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">

<h2 class="w3-center">Automatic Slideshow</h2>

<div class="w3-content w3-section" style="max-width:500px">
  <img class="mySlides" src="//via.placeholder.com/350x150/AAFFAA" style="width:100%">
  <img class="mySlides" src="//via.placeholder.com/350x150/FFAAAA" style="width:100%">
  <img class="mySlides" src="//via.placeholder.com/350x150/AAAAFF" style="width:100%">
</div>
&#13;
&#13;
&#13;

0 个答案:

没有答案