<div class="slideshow-container"> <div class="mySlides fade"> <div class="numbertext">1 / 3</div> <img src="images/1.jpg" style="width:100%"> <div class="text">文本 1</div> </div> <div class="mySlides fade"> <div class="numbertext">2 / 3</div> <img src="images/2.jpg" style="width:100%"> <div class="text">文本 2</div> </div> <div class="mySlides fade"> <div class="numbertext">3 / 3</div> <img src="images/3.jpg" style="width:100%"> <div class="text">文本 3</div> </div> <a class="prev" onclick="plusSlides(-1)"> < </a> <a class="next" onclick="plusSlides(1)"> > </a> </div> <div style="text-align:center"> <span class="dot" onclick="currentSlide(1)"></span> <span class="dot" onclick="currentSlide(2)"></span> <span class="dot" onclick="currentSlide(3)"></span> </div> <script> var slideIndex = 1; 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"; } showSlides(slideIndex ); function plusSlides(n) { showSlides(slideIndex += n); } function currentSlide(n) { showSlides(slideIndex = n); } </script>
这段JS里面有很多不明白的地方,比如
if (n > slides.length) {slideIndex = 1}
if (n < 1) {slideIndex = slides.length}
这两句话是什么意思啊 这个n是一个参数 但是代表什么意思?
还有
slides[slideIndex-1].style.display = "block";
dots[slideIndex-1].className += " active";
不是很理解 请帮忙看一下
ruibin