Switching - Ryan-Rutledge/FlashcardStacks GitHub Wiki
Switching | Finishing | Entering | Leaving | Notes
Switch events are methods executed during key moments of flipping from one card in a stack to another.
- All switch event methods are sent the flashcard's Stack object as a parameter
- Card switch events are handled in the following order:
- onSwitch
- onSwitchLeave
- onSwitchEnter
- onSwitchFinish
Entire stacks can be assigned switch events by setting the fc-on[switch-event]
attribute in the fc_container
class.
<!-- Execute customFinishFunction(stack) every time this stack switches cards -->
<div id='unique_id' class='fc_container' fc-onSwitchFinish="customFinishFunction">
<!-- Stack content -->
</div>
OR
Individual flashcards can be assigned switch events by assigning methods to the FlashCard object through JavaScript.
// Assign onSwitch function to every individual CustomCardClass
CustomCardClass.prototype.onSwitch(stack) {
// Code to execute at beginning of switch event goes here
}
Called at the moment a card begins to leave the stack.
Called at the moment a card has finished entering the stack.
The onEnter
event is called at the moment a new card begins to enter the stack.
The onLeave
event is called at the moment a card leaves the stack, but before a new card has entered.
- Only HTML attributes can assign card switch events to entire stacks.
- Both HTML attributes and JavaScript can assign card switch events to individual cards, but only JavaScript can change or remove them.
- In cases where both a stack and an individual card within in it have their own switch events, the equivalent switch event of the card is handled immediately before the stack's.