html
<span id="startButton" style="cursor:default">[Start]</span>
<span id="stopButton" style="cursor:pointer">[Stop]</span>
JavaScript
//parameters
var pages = [0, 1, 3]; //◄ Select the pages you want to cycle through. 0 is the first one
var timeout = 10000; //◄ Select the time in ms to delay between pages. 10000 is 10 seconds
//maintain a registry of interval in case multiple are triggered to stop them all at once with the stop button
window["intervalIds"]??=[];
tmp=[...pages]
function startCycle() {
(function cycle(){
page = tmp.shift();
if(!tmp.length) tmp=[...pages]
goToPage(page);
window.intervalIds.push(setTimeout(cycle, timeout));
})();
}
function stopCycle() {
console.log("Slideshow Ended")
window.intervalIds.forEach(clearInterval);
}
function goToPage(x) {
document.querySelectorAll(".sf-element-page-tab")[x].click();
}
// Hook html buttons to start and stop functions
document.getElementById("startButton").onclick = startCycle;
document.getElementById("stopButton").onclick = stopCycle;
No comments:
Post a Comment