#offcanvas.js
##Usage
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
###Via data attributes
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.
###Via JavaScript
Call a offcanvas with id myOffcanvas
with a single line of JavaScript:
$('#myOffcanvas').offcanvas(options)
###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. |
###Methods
####.offcanvas(options)
Activates your content as a offcanvas. Accepts an optional options object
.
$('#myOffcanvas').offcanvas({keyboard : false})
####.offcanvas('toggle')
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')
####.offcanvas('show')
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')
####.offcanvas('hide')
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')
###Events 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). |
##Copyright and license Code and documentation copyright 2014 Vitaliy Ralle. Code released under the MIT license. Docs released under Creative Commons.
Thank you very much, it was really practical and great