Widget:NewsLanding/Slider

From TwogPedia
Revision as of 14:53, 12 February 2024 by Couchor (talk | contribs) (Created page with "<script> const container = document.getElementById('news-slider-container'); const prevButton = document.getElementById('prev'); const nextButton = document.getElementById('next'); let currentIndex = 0; function showNews(index) { const offset = -index * 100; container.style.transform = `translateX(${offset}%)`; } function showNextNews() { currentIndex = (currentIndex + 1) % container.children.length; showNews(currentIndex); } functio...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

<script>

 const container = document.getElementById('news-slider-container');
 const prevButton = document.getElementById('prev');
 const nextButton = document.getElementById('next');
 let currentIndex = 0;
 function showNews(index) {
   const offset = -index * 100;
   container.style.transform = `translateX(${offset}%)`;
 }
 function showNextNews() {
   currentIndex = (currentIndex + 1) % container.children.length;
   showNews(currentIndex);
 }
 function showPrevNews() {
   currentIndex = (currentIndex - 1 + container.children.length) % container.children.length;
   showNews(currentIndex);
 }
 nextButton.addEventListener('click', showNextNews);
 prevButton.addEventListener('click', showPrevNews);
 // Auto rotate every 20 seconds
 setInterval(showNextNews, 20000);

</script>