Collapse

Hubble's Collapse component offers an easy to use, simple HTML initialized way to toggle content height via a trigger.

The component uses a small amount of CSS, but mostly JavaScript to provide smooth and consistent transitions no matter the content size.



Basic example

Add the .js-collapse class to clickable element, with the data-collapse-target attribute set as the id of the element you want to toggle.



When the target element is clicked, the .active class is toggled. If the element being clicked is an <a> tag, event.preventDefault(); is called on the click event. This allows you to use <a> tags as click target without needing to worry about stopping the click event.


Options

You can also specify the animation speed and the animation easing function as data attributes. data-collapse-speed defines the animation speed in milliseconds, while data-collapse-easing defines the animation easing via a valid CSS easing property.