1.0.2 • Published 3 years ago

expander.js v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

expander.js

This package makes your HTML elements increase and decrease in an animated way. The best features are toggle elements, increase element, decrease element and reset elements.

This package is still in development. I welcome suggestions for changes that will bring it closer to compliance without overly complicating the code, or useful test cases to add to the test suite.

Contents

Features

Install

npm install expander.js

Usage

1. Add markup (your wrapper has to be relative position and add hidden style as display none)

<style>
  .hidden
   {
    display: none;
   }
  .cs-expander-items
  {
    position: relative;
  }
</style>
<div class="cs-expander">
    <div class="cs-expander-items">
        <div class="item"></div>
        <div class="item"></div>
        <div class="item"></div>
        <div class="item"></div>
    </div>
</div>

2. Initialize your class

<script src="expander.js/dist/expander.js"></script>
<script>
    let expander = new Expander('.cs-expander-items',{toggle:true,resetable:true})
</script>

Options

OptionTypeDescription
showNumberDefault: 4. Number of items initially shown.
increaseNumberDefault: 3. Number of items to add per click.
decreaseNumberDefault: 3. Number of items to remove per click, if it is zero it will use increase variable.
toggleBooleanDefault: false. Append a toggle button, and functionality.
resetableBooleanDefault: false. Append a reset button, and functionality.
unaryBooleanDefault: false. Removes increase and decrease buttons if toggle is true
increaseBtnStringDefault: '.cs-expander-increase-btn'. Button container for increasing items
increaseBtnValueStringDefault: 'Increase Items'. Increase button text
toggleBtnStringDefault: '.cs-expander-toggle-btn'. Button container for toggling
toggleBtnValueStringDefault: 'Toggle Items'. Toggle button text
decreaseBtnStringDefault: '.cs-expander-decrease-btn'. Button container for decreasing items
decreaseBtnValueStringDefault: 'Decrease Items'. Decrease button text
resetBtnStringDefault: '.cs-expander-reset-btn'. Button container for reset expander
resetBtnValueStringDefault: 'Collapse'. Reset button text
animationDurationNumberDefault: 1. Animation Duration

Methods

The slider returns a slider object with some properties and methods once it's initialized:

{
  collapse: collapse(),
  increaseItem: increaseItem(),
  decreaseItem: decreaseItem(),
  getActiveItems: getActiveItems, // Array
  getHiddenItems: getHiddenItems, // Array
}

collapse

Resets expander

expander.collapse();

increaseItem, decreaseItem

Increase or decrease items by number or default.

expander.increaseItem();
expander.increaseItem(5);

expander.decreaseItem();
expander.decreaseItem(5);

getActiveItems

Get all shown elements as an node array

expander.getActiveItems();

getHiddenItems

Get all hidden elements as an node array

expander.getHiddenItems();

License

This project is available under the MIT license.

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago