Offcanvas

Build hidden sidebars.

How it works

Offcanvas act as a sidebar component that can be toggled via JavaScript. It can appears from any edge of the viewport. Any html element can be used as a trigger to toggle the attached offcanvas. When click the trigger, JavaScript toggle the offcanvas’s translate style property between it’s original value and none behind the scene. So it is important to set offcanvas’s initial state properly.

Examples

Examples in this page use Tailwindcss to apply styles.

link trigger

Backdrop

While offcanvas is open, a backdrop is created and appended to document.body. There is no class applied to the backdrop by default. You can set the backdrop class name via backdropClassName config option when instantiating the offcanvas instance. To prevent backdrop from creating, sets the backdrop config option to false.

Placement

Setting translate style property to control the offcanvas initial placement, then the plugin handle all of the other things.

Config

NameTypeDefaultDescription
backdropbooleantrueWhether to create a backdrop while offcanvas is open.
backdropClassNameundefined | stringundefinedClass name applied to backdrop.

Methods

MethodDescription
toggleToggles an offcanvas to shown or hidden.
showShows an offcanvas
hideHides an offcanvas