No edit summary |
No edit summary |
||
Line 17: | Line 17: | ||
mainImageDiv.innerHTML = imageHtml + '<div class="loadingBar"></div>'; | mainImageDiv.innerHTML = imageHtml + '<div class="loadingBar"></div>'; | ||
resetLoadingBar(); | resetLoadingBar(); | ||
} | } | ||
Line 43: | Line 24: | ||
image.addEventListener('click', function() { | image.addEventListener('click', function() { | ||
setMainImage(this.innerHTML); | setMainImage(this.innerHTML); | ||
lastSelectedIndex = currentIndex; | |||
currentIndex = index; // Update the current index | currentIndex = index; // Update the current index | ||
resetLoadingBar(); // Reset the loading bar on click | |||
}); | }); | ||
}); | }); | ||
} | } | ||
var lastSelectedIndex = -1; | |||
var currentIndex = 0; | var currentIndex = 0; | ||
function getNextIndex(imagesLength) { | |||
var nextIndex; | |||
do { | |||
nextIndex = Math.floor(Math.random() * imagesLength); | |||
} while (nextIndex === lastSelectedIndex); | |||
return nextIndex; | |||
} | |||
function rotateImages() { | function rotateImages() { | ||
var images = document.querySelectorAll('.carousel .dpImage'); | var images = document.querySelectorAll('.carousel .dpImage'); | ||
setInterval(function() { | setInterval(function() { | ||
currentIndex = getNextIndex(images.length); | |||
setMainImage(images[currentIndex].innerHTML); | setMainImage(images[currentIndex].innerHTML); | ||
currentIndex+ | lastSelectedIndex = currentIndex; | ||
currentIndex = (currentIndex + 1) % images.length; | |||
}, 10000); // Rotates every 10000 milliseconds (10 seconds) | }, 10000); // Rotates every 10000 milliseconds (10 seconds) | ||
} | |||
function resetLoadingBar() { | |||
var loadingBar = document.querySelector('.loadingBar'); | |||
loadingBar.style.width = '0%'; // Reset the width | |||
var intervalTime = 10000; // Same as image rotation interval | |||
setTimeout(function() { loadingBar.style.width = '100%'; }, 0); | |||
} | } | ||
Revision as of 14:03, 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 setMainImage(imageHtml) { var mainImageDiv = document.querySelector('.mainImage'); mainImageDiv.innerHTML = imageHtml + '<div class="loadingBar"></div>'; resetLoadingBar(); } function addClickEventToImages() { var images = document.querySelectorAll('.carousel .dpImage'); images.forEach(function(image, index) { image.addEventListener('click', function() { setMainImage(this.innerHTML); lastSelectedIndex = currentIndex; currentIndex = index; // Update the current index resetLoadingBar(); // Reset the loading bar on click }); }); } var lastSelectedIndex = -1; var currentIndex = 0; function getNextIndex(imagesLength) { var nextIndex; do { nextIndex = Math.floor(Math.random() * imagesLength); } while (nextIndex === lastSelectedIndex); return nextIndex; } function rotateImages() { var images = document.querySelectorAll('.carousel .dpImage'); setInterval(function() { currentIndex = getNextIndex(images.length); setMainImage(images[currentIndex].innerHTML); lastSelectedIndex = currentIndex; currentIndex = (currentIndex + 1) % images.length; }, 10000); // Rotates every 10000 milliseconds (10 seconds) } function resetLoadingBar() { var loadingBar = document.querySelector('.loadingBar'); loadingBar.style.width = '0%'; // Reset the width var intervalTime = 10000; // Same as image rotation interval setTimeout(function() { loadingBar.style.width = '100%'; }, 0); } // Call the functions when the window loads window.onload = function() { addClickEventToImages(); rotateImages(); setMainImage(document.querySelector('.carousel .dpImage').innerHTML); // Set the first image as the default };