el-transition
Install
$ npm install el-transition
$ yarn add el-transition
Purpose
The purpose of this package is to handle enter/leave transition using classes or data attributes. This is similar to the implementations you find in vue.js and alpine.js.
Usage
Both class based and dataset attributes are supported.
To hide and show elements an implemenation of the class hidden
is required.
el-transition
exports three async functions enter
, leave
, and toggle
. Each function expects an HTML DOM element as the first argument and optional transition name as the second.
// app.js { } // remove element when close { } // calls enter or leave based on presence of the class hidden { ;}
Dataset Attributes
When using dataset attributes el-transtion expects the following.
- data-transtion-enter: Applied during the entire entering phase.
- data-transition-enter-start: Added before element is inserted, removed one frame after element is inserted.
- data-transition-enter-end: Added one frame after element is inserted (at the same time enter-start is removed), removed when transition/animation finishes.
- data-transition-leave: Applied during the entire leaving phase.
- data-transition-leave-start: Added immediately when a leaving transition is triggered, removed after one frame.
- data-transition-leave-end: Added one frame after a leaving transition is triggered (at the same time leave-start is removed), removed when the transition/animation finishes.
Example
<!-- dropdown.html --> Options <!-- declare enter leave anmiations using data attributes --> <!-- Menu links -->
const dropdownMenu = documentconst dropdownBtn = document { } { } { } dropdownBtn
Transition Name Option
You may specificy a transition name and el-transtion will handle applying the inferred css classses at the each stage. If data attributes are set, those will take precedence.
Using the example transition name dropdown
we need can declare a class per stage.
- .dropdown-enter: Applied during the entire entering phase.
- .dropdown-enter-start: Added before element is inserted, removed one frame after element is inserted.
- .dropdown-enter-end: Added one frame after element is inserted (at the same time enter-start is removed), removed when transition/animation finishes.
- .dropdown-leave: Applied during the entire leaving phase.
- .dropdown-leave-start: Added immediately when a leaving transition is triggered, removed after one frame.
- .dropdown-leave-end: Added one frame after a leaving transition is triggered (at the same time leave-start is removed), removed when the transition/animation finishes.
// application.scss .dropdown-enter .dropdown-enter-start .dropdown-enter-end .dropdown-leave .dropdown-leave-start .dropdown-leave-end
<!-- dropdown.html --> Options <!-- Menu links -->
// app.js const dropdownMenu = documentconst dropdownBtn = document { } { } { } dropdownBtn