It can start as expanded or collapsed. You just need to add/remove '--is-active' class and toggle aria attributes.
Lorem ipsum dolor sit amet consectetur adipisicing elit. Ea deleniti nisi maxime sequi corporis labore repellat impedit, id vel, esse ad, culpa praesentium? Nobis quam fugiat natus, at nisi cumque.
var SimpleExample = new Collapsify()
Data attributes (ID):
Trigger elements -> data-{nameSpace}-control
Content elements -> data-{nameSpace}-content
- nameSpace default value: 'collapsify'
Same look and feel but different triggers, collapse but now with nameSpace attribute set as 'different'.
var different = new Collapsify({
nameSpace:'different',
})
Data attributes (ID):
Trigger elements -> data-{nameSpace}-control
Content elements -> data-{nameSpace}-content
- nameSpace value: 'different'
Here it is shown another collapse, but now one of the contents has its own nested triggerButton-content.
var nested = new Collapsify({
nameSpace: "nested",
closeOthers: false,
});
'closeOthers' argument will define if the rest of the contents would close or not when you click on one of them.
It works as a classic accordion component. The same 'closeOthers' attribute functionality applies here too.
Second content : Lorem ipsum, dolor sit amet consectetur adipisicing elit. Fugit repellat optio ab fugiat pariatur eius dolores omnis ullam nostrum ad vitae praesentium ex veniam veritatis consequatur, quidem consectetur nemo? Voluptatibus.
var accordion = new Collapsify({
nameSpace: "accordion",
});
Data attributes (ID):
Trigger elements -> data-{nameSpace}-control
Content elements -> data-{nameSpace}-content
- nameSpace value: 'accordion'
var tab = new Collapsify({
nameSpace: "tab",
isTab: true,
dropdownElement: HTMLElement,
});
Common tabs functionality. Two new attributes to take into consideration:
- isTab: boolean
- dropdownElement: HTMLSelectElement for tablets/mobiles devices.
var tab = new Collapsify({
nameSpace: "tabTwo",
isTab: true,
dropdownElement: HTMLElement,
});
Another tabs example but this time with no initial active elements.
var tab = new Collapsify({
nameSpace: "tabThird",
closeOthers: true,
isTab: true,
dropdownElement: document.querySelector(".js--select-item-c"),
onSlideStart: (isOpen, contentID) => {
...
},
onSlideEnd: (isOpen, contentID) => {
...
}
});
This example shows how you can use this library with other js libraries, it is important to use both 'onSlideStart' and 'onSliderEnd' callbacks in order to initialize/destroy.