MediaWiki:Common.js: Difference between revisions

MediaWiki interface page
No edit summary
No edit summary
Line 13: Line 13:
}
}


const images = document.querySelectorAll('.dpImage');
function rotateImages() {
const mainImage = document.querySelector('.mainImage');
    var images = document.querySelectorAll('.carousel .dpImage');
let currentIndex = 0;
    var mainImageDiv = document.querySelector('.mainImage');
    var currentIndex = 0;


function showImage(index) {
    setInterval(function() {
  mainImage.innerHTML = images[index].innerHTML;
        if (currentIndex >= images.length) {
  images.forEach((image, i) => {
            currentIndex = 0;
      if (i === index) {
        }
        image.classList.add('selected');
      } else {
        image.classList.remove('selected');
      }
  });
}


function rotateImages() {
        var selectedImage = images[currentIndex].innerHTML;
  showImage(currentIndex);
        mainImageDiv.innerHTML = selectedImage;
  currentIndex = (currentIndex + 1) % images.length;
        currentIndex++;
    }, 10000); // Rotates every 10000 milliseconds (10 seconds)
}
}


setInterval(rotateImages, 5000); // Change the image every 5 seconds (adjust as needed)
// Call the function when the window loads
showImage(currentIndex); // Initial display
window.onload = rotateImages;

Revision as of 13:55, 31 January 2024

/* Any JavaScript here will be loaded for all users on every page load. */


var coll = document.getElementsByClassName("collapsible");
var i;

for (i = 0; i < coll.length; i++) {
  coll[i].addEventListener("click", function() {
    this.classList.toggle("active");
    var content = this.nextElementSibling;
    $(content).toggle('fast');
  });
}

function rotateImages() {
    var images = document.querySelectorAll('.carousel .dpImage');
    var mainImageDiv = document.querySelector('.mainImage');
    var currentIndex = 0;

    setInterval(function() {
        if (currentIndex >= images.length) {
            currentIndex = 0;
        }

        var selectedImage = images[currentIndex].innerHTML;
        mainImageDiv.innerHTML = selectedImage;
        currentIndex++;
    }, 10000); // Rotates every 10000 milliseconds (10 seconds)
}

// Call the function when the window loads
window.onload = rotateImages;