Skip to content

Instantly share code, notes, and snippets.

@themorgantown
Created January 3, 2024 20:26
Show Gist options
  • Save themorgantown/f6b3695afb4b3e6d85f9333890958468 to your computer and use it in GitHub Desktop.
Save themorgantown/f6b3695afb4b3e6d85f9333890958468 to your computer and use it in GitHub Desktop.
// run on scene load....
// Function to update and set up the checkbox
function setupAutoPlayToggle() {
var checkBox = document.getElementById('autoPlayToggle'); // Get the checkbox element
if (checkBox) {
var autoPlayEnabled = localStorage.getItem('autoPlayEnabled') === 'true'; // Check if auto play is enabled
checkBox.checked = autoPlayEnabled; // Set the checkbox state based on the auto play status
checkBox.addEventListener('change', function() { // Add event listener for checkbox change
localStorage.setItem('autoPlayEnabled', this.checked); // Update the auto play status in local storage
});
}
}
// Call the setup function to update the checkbox state
setupAutoPlayToggle();
// Function to handle the end of a timeline
function handleAutoplay(event) {
if (localStorage.getItem('autoPlayEnabled') === 'true') { // Check if auto play is enabled
// Ensure that we react only to the Main Timeline completion
//if (event.timelineName === 'Main Timeline') { // Check if the completed timeline is the Main Timeline
hypeDocument.showNextScene(hypeDocument.kSceneTransitionCrossfade, 0.1); // Show the next scene with a crossfade transition
setTimeout(function() {
hypeDocument.continueTimelineNamed('Main Timeline', hypeDocument.kDirectionForward, false); // Continue the Main Timeline after a half-second delay
}, 500); // half-sec delay
//}
}
}
// Register the HypeTimelineComplete event listener for this scene
if (!window.HYPE_eventListeners) {
window.HYPE_eventListeners = [];
}
window.HYPE_eventListeners.push({
type: "HypeTimelineComplete",
callback: handleAutoplay
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment