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.
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" > |
3 |
< script src = "jquery.min.js" ></ script > |
4 |
< script src = "bootstrap.min.js" ></ script > |
2. Create a sidebar that has a negative left margin when collapsed.
1 |
< div class = "col-md-3" id = "sidebar" > |
03 |
transition: margin 0.3 s ease; |
11 |
@media ( min-width : 992px ) { |
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 > |
8 |
transition: width 0.3 s ease; |
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.