Get pictures from folder with javascript to my website

时间:2018-06-04 17:19:00

标签: javascript jquery html

I have a local website with .html file and I want my slideshow to automatically display pictures from a folder and display them without the need to add it manually one by one. Right now I have to add for every new image I want.

Here is my code:

   <img class="mySlides myImg"  src="Images/Image_01.jpeg" alt="01" width="620" height="340">
   <img class="mySlides myImg"  src="Images/Image_02.jpeg" alt="02" width="620" height="340">

 <!-- Slider Image Script -->
                 <script>
                 var slideIndex = 1;
                 showDivs(slideIndex);

                 function plusDivs(n) {
                 showDivs(slideIndex += n);
                 }

                 function currentDiv(n) {
                 showDivs(slideIndex = n);
                 }

                 function showDivs(n) {
                 var i;
                 var x = document.getElementsByClassName("mySlides");
                 var dots = document.getElementsByClassName("demo");
                 if (n > x.length) {slideIndex = 1}    
                 if (n < 1) {slideIndex = x.length}
                 for (i = 0; i < x.length; i++) {
                     x[i].style.display = "none";  
                  }
                 for (i = 0; i < dots.length; i++) {
                 dots[i].className = dots[i].className.replace(" w3-white", "");
                 }
                 x[slideIndex-1].style.display = "block";  
                 dots[slideIndex-1].className += " w3-white";
                 }
                 </script>

0 个答案:

没有答案