Hi, I'm trying to create a button that:
- on click, starts a timeline, adds class "clicked"
- on second click, reverses the timeline, and removes the class "clicked", thereby restores original button label and color.
I can get Step 1 working, but on second click, it just restarts the timeline.
I looked at this earlier thread as a reference, but was not able to use it to solve my problem: Toggle animation Play / Pause
Here's my code:
// Function: Check if class "clicked" exists, and if it does, reverse the timeline
var button = hypeDocument.getElementById('clickHere');
if (button.classList.contains('clicked')) {
button.classList.remove('clicked');
button.innerHTML = "Click Here";
hypeDocument.continueTimelineNamed('box opens', hypeDocument.kDirectionReverse, false)
}
This is the function that starts the timeline, which works:
// Start Timeline on click
var button = hypeDocument.getElementById('clickHere');
button.innerHTML = "Reverse Timeline";
button.classList.add('clicked');
hypeDocument.startTimelineNamed('box opens', hypeDocument.kDirectionForward);
Here's a video of what happens:
And here's my Hype file:
toggle-timeline-play-reverse.hype.zip (18.4 KB)
Any help is appreciated. Thanks!