This time I will share jQuery Plugin and tutorial about Expand And Collapse Anything W1ith jQuery – Expander, hope it will help you in programming stack.
Expander is a powerful and multipurpose jQuery content toggle plugin for toggling the visibility of any content blocks with slide up & slide down animations.
It uses Popper.js library to provides a smart auto-position functionality that automatically re-position the content to make it stay within the screen.
Ideal for creating smooth accordion and dropdown components on your web app.
How to use it:
1. Insert the Expander plugin’s files into the HTML file.
2 |
< script src = "/path/to/cdn/jquery.slim.min.js" ></ script > |
4 |
< link rel = "stylesheet" href = "/path/to/dist/jquery.expander.min.css" /> |
5 |
< script src = "/path/to/dist/jquery.expander.min.js" ></ script > |
2. Create a single expanding block with the following data
attributes:
- data-expander: Required
- data-toggle: Toggle element
- data-body: Element to toggle
1 |
< div class = "accordion" data-expander> |
2 |
< div class = "accordion__head" data-toggle> |
5 |
< div class = "accordion__body" data-body> |
3. Create connected expanding blocks (accordion):
01 |
< div class = "accordion" data-expander = "my-accordion" > |
02 |
< div class = "accordion__head" data-toggle> |
05 |
< div class = "accordion__body" data-body> |
10 |
< div class = "accordion" data-expander = "my-accordion" > |
11 |
< div class = "accordion__head" data-toggle> |
14 |
< div class = "accordion__body" data-body> |
3. Create a dropdown component that allows the user to expand/collapse content by hovering over the toggle element.
2 |
< div class = "dropdown__head" data-toggle>Hover Me</ div > |
3 |
< div class = "dropdown__body" data-body> |
1 |
$( '.dropdown' ).expander({ |
4. All possible options to customize the expander plugin.
01 |
$( 'element' ).expander({ |
16 |
animationDuration: 300, |
34 |
dropdownHoverable: true , |
5. Callback functions.
01 |
$( 'element' ).expander({ |
03 |
onOpen: function (event, expander){ |
07 |
onClose: function (event, expander){ |
11 |
onToggle: function (event, expander){ |
15 |
onInit: function (expander){ |
Changelog:
2020-11-25
- Added popper options
- Fixed minor bugs