Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trigger data-toggle=offcanvas event

I'm using a great bootstrap 3 layout that use an "offcanvas" sidebar. All is working great on all screen size.

The HTML tag that triggered the sidebar is :

<a href="#" class="navbar-btn sidebar-toggle" data-toggle="offcanvas" role="button">

How could i trigger this event with jquery ?? Sometimes i need to toggle the sidebar on user event, somtimes i need to display the page with the sidebar hidden.

I try to trigger the click event with jquery but it does nothing as there isn't any onClick event on this tag...

Thanks for your help.

like image 655
Seb Avatar asked Oct 31 '22 18:10

Seb


2 Answers

Use the collapse() method that comes with Bootstrap. Something like

$('.sidebar-toggle').collapse();

should work.

See the link below for more info on collapse():

http://getbootstrap.com/javascript/#collapse-usage

like image 95
cfj Avatar answered Nov 10 '22 03:11

cfj


Classname: "sidebar-collapse" is responsible for collapsing the sidebar. For example: <body id="bodyContainer" class="hold-transition skin-blue sidebar-mini sidebar-collapse">
This is for collapsed sidebar.

<body id="bodyContainer" class="hold-transition skin-blue sidebar-mini">

This is for non-collapsed sidebar.

So, basically you have to write jquery function to remove/include class "sidebar-mini"

like image 28
Om Sao Avatar answered Nov 10 '22 05:11

Om Sao