Creating Collapsible Bootstrap Sidebars with jQuery CSS - Download Creating Collapsible Bootstrap Sidebars with jQuery and CSS

Download Creating Collapsible Bootstrap Sidebars with jQuery and CSS

Posted on

This time I will share jQuery Plugin and tutorial about Creating Collapsible Bootstrap Sidebars with jQuery and CSS, hope it will help you in programming stack.

Creating Collapsible Bootstrap Sidebars with jQuery CSS - Download Creating Collapsible Bootstrap Sidebars with jQuery and CSS
File Size: 7.67 KB
Views Total: 23885
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   

With some additional CSS rules and a little jQuery, we can create animated collapsible sidebars for your Bootstrap project.

How to use it:

1. You must have jQuery library installed in your Bootstrap project.

1 <link rel="stylesheet" href="bootstrap.min.css">
2   ...
3 <script src="jquery.min.js"></script>
4 <script src="bootstrap.min.js"></script>
5   ...

2. Create a sidebar that has a negative left margin when collapsed.

1 <div class="col-md-3" id="sidebar">
2   ...
3 </div>
01 #sidebar {
02   /* for the animation */
03   transition: margin 0.3s ease;
04 }
05  
06 .collapsed {
07   /* hide it for small displays*/
08   display: none;
09 }
10  
11 @media (min-width: 992px) {
12   .collapsed {
13     display: block;
14     /* same width as sidebar */
15     margin-left: -25%;
16   }
17 }

3. Add a sidebar toggle button to your main content. The main content will changes from .col-md-9 to .col-md-12 when the sidebar is collapsed, occupying the remaining space.

1 <div class="col-md-9" id="content">
2   <button type="button" class="btn btn-default toggle-sidebar">Toggle sidebar</button>
3 </div>
1 #row-main {
2   /* necessary to hide collapsed sidebar */
3   overflow-x: hidden;
4 }
5  
6 #content {
7   /* for the animation */
8   transition: width 0.3s ease;
9 }

4. To toggle the sidebar, just switch the CSS classes.

1 $("#sidebar").toggleClass("collapsed");
2 $("#content").toggleClass("col-md-12 col-md-9");

This awesome jQuery plugin is developed by nunof07. For more Advanced Usages, please check the demo page or visit the official website.

source : jqueryscript.net