Untitled

mail@pastecode.io avatarunknown
plain_text
a month ago
822 B
2
Indexable
Never
const carousel = document.querySelector('#carousel-e6bee4dc');
const slides = document.querySelectorAll('.sc-feryYK.cVoPex');
let currentSlideIndex = 0;

function showSlide(index) {
  slides.forEach((slide, i) => {
    if (i === index) {
      slide.style.display = 'block';
    } else {
      slide.style.display = 'none';
    }
  });
}

function rotateCarouselWithoutNavigation() {
  // 1. Save the current scroll position
  const savedScrollPosition = window.scrollY;

  // 2. Rotate the carousel
  currentSlideIndex = (currentSlideIndex + 1) % slides.length;
  showSlide(currentSlideIndex);

  // 3. Restore the saved scroll position
  window.scrollTo(0, savedScrollPosition);
}

// Use this function to rotate the carousel every 3 seconds
setInterval(rotateCarouselWithoutNavigation, 3000);