Switching - Ryan-Rutledge/FlashcardStacks GitHub Wiki

Card Switch Events

Switching | Finishing | Entering | Leaving | Notes


Switch Events

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

Example

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
}

Switching

fc-onSwitch

Called at the moment a card begins to leave the stack.

Finishing

fc-onSwitchFinish

Called at the moment a card has finished entering the stack.

Entering

fc-onEnter

The onEnter event is called at the moment a new card begins to enter the stack.

Leaving

fc-onLeave

The onLeave event is called at the moment a card leaves the stack, but before a new card has entered.

Notes

  • 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.
⚠️ **GitHub.com Fallback** ⚠️