Reset
If you want to return to its original state (without slides), simply add the following:
$('button.close').click(function() { $('.opened').removeClass('opened'); });
Tracking the full story in this case is redundant.
Demo: http://jsfiddle.net/VA5Pv/4/
Story
A few answers suggested using the story. Most of them used an array that tracks the slides that the user opened, and then simply pops them out to βreturnβ.
var history = []; $('#content div').click(function() { var move = $(this).attr('data-move'); history.push(move); SlideOut(); }); $('button.close').click(function() { history.pop(); SlideOut(); }); function SlideOut() { var element = history[history.length - 1];
This would be necessary if you would like to allow the user to open any number of slides in any order and always provide them with a button to return to the previously opened slide.
Sequence
Another solution could be to store all slide IDs in an array and save a counter that tells you which slide you are on. A return would mean decrementing the counter if it is no longer zero, and then switches to this particular slide.
This would be useful if you were trying to create something like a presentation where each slide opens in sequence and the transitions are completely linear.
That is why I asked you to clarify what you were trying to build. Depending on the use case, the solutions could be significantly different and much more complex than what you were really looking for.
Thanks for accepting my response and welcome StackOverflow. Feel free to support all the answers you found useful, even if they did not answer your question enough.
source share