javascript - w3.css slideshow: How to add automatic slideshow functionality -


i want make slideshow w3.css library slideshow automatically every 4-5 seconds. can found @ w3schools editor.

more documentation of w3.css slideshows can found here

i need somehow add code make images slideshow automatically keep bullets background , make arrows work:

var slideindex = 0; carousel(); function carousel() {     var i;     var x = document.getelementsbyclassname("myslides");     (i = 0; < x.length; i++) {       x[i].style.display = "none";      }     slideindex++;     if (slideindex > x.length) {slideindex = 1}      x[slideindex-1].style.display = "block";      settimeout(carousel, 2000); // change image every 2 seconds } 

here complete code:

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}    (i = 0; < x.length; i++) {       x[i].style.display = "none";      }    (i = 0; < dots.length; i++) {       dots[i].classname = dots[i].classname.replace(" w3-white", "");    }    x[slideindex-1].style.display = "block";      dots[slideindex-1].classname += " w3-white";  }
.myslides {display:none}  .w3-left, .w3-right, .w3-badge {cursor:pointer}  .w3-badge {height:13px;width:13px;padding:0}
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">    <div class="w3-container">    <h2>slideshow indicators</h2>    <p>an example of using buttons indicate how many slides there in slideshow, , slide user viewing.</p>  </div>    <div class="w3-content w3-display-container" style="max-width:800px">    <img class="myslides" src="https://cdn-s3.si.com/styles/marquee_large_2x/s3/images/trump-5.jpg" style="width:100%">    <img class="myslides" src="https://i.ytimg.com/vi/vpevtnrk-_m/maxresdefault.jpg" style="width:100%">    <img class="myslides" src="https://img00.deviantart.net/a73e/i/2015/261/4/3/the_magic_world_by_chibionpu-d4ol7wm.jpg" style="width:100%">    <div class="w3-center w3-container w3-section w3-large w3-text-white w3-display-bottommiddle" style="width:100%">      <div class="w3-left w3-hover-text-khaki" onclick="plusdivs(-1)">&#10094;</div>      <div class="w3-right w3-hover-text-khaki" onclick="plusdivs(1)">&#10095;</div>      <span class="w3-badge demo w3-border w3-transparent w3-hover-white" onclick="currentdiv(1)"></span>      <span class="w3-badge demo w3-border w3-transparent w3-hover-white" onclick="currentdiv(2)"></span>      <span class="w3-badge demo w3-border w3-transparent w3-hover-white" onclick="currentdiv(3)"></span>    </div>  </div>

setinterval(function(){     slideindex++;     currentdiv(slideindex); }, 2000); 

add code example @ end


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -