Template:Slideshow

From Eiserner Vorhang
Revision as of 01:22, 30 December 2024 by Maximusthezorua (talk | contribs) (Created page with "<div class="slideshow"> <button class="prev">Prev</button> <button class="next">Next</button> <div class="image-container" id="image-{{IMAGE_ID}}"></div> <!-- Add your images here, like this --> <img src="https://example.com/image1.jpg" alt="Image 1"> <img src="https://example.com/image2.jpg" alt="Image 2"> <!-- ... --> </div> <script> // Get the slideshow elements const slideshow = document.querySelector('.slideshow'); const prevButton = document.qu...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search
 <button class="prev">Prev</button>
 <button class="next">Next</button>
 <img src="https://example.com/image1.jpg" alt="Image 1">
 <img src="https://example.com/image2.jpg" alt="Image 2">

<script>

 // Get the slideshow elements
 const slideshow = document.querySelector('.slideshow');
 const prevButton = document.querySelector('.prev');
 const nextButton = document.querySelector('.next');
 const imageContainers = document.querySelectorAll('.image-container');
 // Set up event listeners for buttons
 prevButton.addEventListener('click', showPreviousImage);
 nextButton.addEventListener('click', showNextImage);
 // Initialize the slideshow with the first image
 let currentImageIndex = 0;
 imageContainers[currentImageIndex].appendChild(slideShowImages[0]);
 // Function to show the previous image
 function showPreviousImage() {
   if (currentImageIndex > 0) {
     currentImageIndex--;
     updateSlideshow();
   }
 }
 // Function to show the next image
 function showNextImage() {
   if (currentImageIndex < slideShowImages.length - 1) {
     currentImageIndex++;
     updateSlideshow();
   }
 }
 // Function to update the slideshow
 function updateSlideshow() {
   const imageContainer = document.querySelector(`#image-${currentImageIndex}`);
   imageContainer.innerHTML = ;
   imageContainers[currentImageIndex].appendChild(slideShowImages[currentImageIndex]);
 }

</script>

 <img src="https://example.com/image1.jpg" alt="Image 1">
 <img src="https://example.com/image2.jpg" alt="Image 2">