The offcanvas plugin toggles your hidden content on demand, via data attributes or JavaScript. It also adds .offcanvas-open
to the <body>
to override default scrolling behavior and generates a .offcanvas-backdrop
to provide a click area for dismissing shown offcanvas when clicking outside the offcanvas.
<!-- Button trigger offcanvas -->
<button class="btn btn-primary" data-toggle="offcanvas" data-target="#myOffcanvas" data-fade="false">
Launch offcanvas
</button>
<!-- Offcanvas -->
<div class="offcanvas" id="myOffcanvas" role="navigation" aria-labelledby="myOffcanvasLabel" aria-hidden="true">
<button class="btn btn-primary" data-dismiss="offcanvas">Close</button>
Offcanvas
</div
Activate a offcanvas without writing JavaScript. Set data-toggle="offcanvas"
on a controller element, like a button, along with a data-target="#foo"
or href="#foo"
to target a specific offcanvas to toggle.
Call a offcanvas with id myOffcanvas
with a single line of JavaScript:
$('#myOffcanvas').offcanvas(options)
Options can be passed via data attributes or JavaScript. For data attributes, append the option name to data-
, as in data-fade="false"
.
Name | type | default | description |
---|---|---|---|
fade | boolean | true | Includes a offcanvas-backdrop element. Alternatively, specify false for a disable backdrop overlay. |
keyboard | boolean | true | Closes the offcanvas when escape key is pressed |
show | boolean | true | Shows the offcanvas when initialized. |
Activates your content as a offcanvas. Accepts an optional options object
.
$('#myOffcanvas').offcanvas({keyboard : false})
Manually toggles a offcanvas. Returns to the caller before the offcanvas has actually been shown or hidden (i.e. before the shown.vr.offcanvas
or hidden.vr.offcanvas
event occurs).
$('#myOffcanvas').offcanvas('toggle')
Manually opens a offcanvas. Returns to the caller before the offcanvas has actually been shown (i.e. before the shown.vr.offcanvas
event occurs).
$('#myOffcanvas').offcanvas('show')
Manually hides a offcanvas. Returns to the caller before the offcanvas has actually been hidden (i.e. before the hidden.vr.offcanvas
event occurs).
$('#myOffcanvas').offcanvas('hide')
Offcanvas class exposes a few events for hooking into offcanvas functionality.
Event Type | Description |
---|---|
show.vr.offcanvas | This event fires immediately when the show instance method is called. |
shown.vr.offcanvas | This event is fired when the offcanvas has been made visible to the user (will wait for CSS transitions to complete). |
hide.vr.offcanvas | This event is fired immediately when the hide instance method has been called. |
hidden.vr.offcanvas | This event is fired when the offcanvas has finished being hidden from the user (will wait for CSS transitions to complete). |
Code and documentation copyright 2014 Vitaliy Ralle. Code released under the MIT license.
Thank you very much, it was really practical and great