Jump to content
shmoonkiepoonks

Need 2 Automatic Slideshows on the Same Page

Recommended Posts

I like the automatic slideshow in the example here: https://www.w3schools.com/howto/tryit.asp?filename=tryhow_js_slideshow_auto, but would like 2 slideshows on one page. When I try to do this myself, one slideshow plays and finishes, then the other one starts and finishes. I would like them to start at the same time and loop and like the caption option but don't necessarily need the "dots".

Share this post


Link to post
Share on other sites

For that example, the easiest way would be to use different class names for your other slideshow.  So use mySlides2 and dots2, for example, and make a copy of that Javascript code with a different function to run the second slideshow with the other class names.

  • Like 1

Share this post


Link to post
Share on other sites

Can anyone elaborate on this? I'm good with HTML & CSS - but have hardly any experience using JS - I was able to get the 2 slideshows working, and they were able to be clicked left and right to the new slides, however, wanting to change these 2 slideshows to automatic has been a headache. I have made the changes the moderator suggested, changing the 2nd slide show class names mySlides2 and dots2... but don't know where to go from here... I don't understand how to make a "different function to run the second slideshow with the other class names." Thank you for any response. Here is where I am at:

<script>
var slideIndex = 0;
showSlides();

function showSlides() {
  var i;
  var slides = document.getElementsByClassName("mySlides1");
  var dots = document.getElementsByClassName("dot");
  for (i = 0; i < slides.length; i++) {
    slides.style.display = "none";  
  }
  slideIndex++;
  if (slideIndex > slides.length) {slideIndex = 1}    
  for (i = 0; i < dots.length; i++) {
    dots.className = dots.className.replace(" active", "");
  }
  slides[slideIndex-1].style.display = "block";  
  dots[slideIndex-1].className += " active";
  setTimeout(showSlides, 2000); // Change image every 2 seconds
}
</script>


<script>
var slideIndex = 0;
showSlides();

function showSlides() {
  var i;
  var slides = document.getElementsByClassName("mySlides2");
  var dots = document.getElementsByClassName("dot2");
  for (i = 0; i < slides.length; i++) {
    slides.style.display = "none";  
  }
  slideIndex++;
  if (slideIndex > slides.length) {slideIndex = 1}    
  for (i = 0; i < dots.length; i++) {
    dots.className = dots.className.replace(" active", "");
  }
  slides[slideIndex-1].style.display = "block";  
  dots[slideIndex-1].className += " active";
  setTimeout(showSlides, 2000); // Change image every 2 seconds
}
</script>

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...