I'm trying to get a togglable sidebar:
No sidebar:
>> | Main text
| goes here
With sidebar:
H1 << | Main text
H2 | goes here
(here is an example of the behaviour: http://pythonhosted.org/cloud_sptheme -- see the button on sidebar. It's not easy to use its code base, because it's not bootstrap-based)
I started from a working example which uses Bootstrap 2 and jQuery 1.8: jsfiddle, SO question, and tried to make it work on Bootstrap 3. Here's a code (code on bootply):
javascript:
$.asm = {};
$.asm.panels = 1;
function sidebar(panels) {
$.asm.panels = panels;
if (panels === 1) {
$('#content').removeClass('col-md-9');
$('#content').addClass('col-md-12');
$('#sidebar1').removeClass('show');
$('#sidebar1').addClass('hide');
} else if (panels === 2) {
$('#content').removeClass('col-md-12');
$('#content').addClass('col-md-9');
$('#sidebar1').removeClass('hide');
$('#sidebar1').addClass('show');
}
}
$('#toggleSidebar').click(function() {
if ($.asm.panels === 1) {
$('#toggleSidebar').addClass('fa-backward');
$('#toggleSidebar').removeClass('fa-forward');
return sidebar(2);
} else {
$('#toggleSidebar').removeClass('fa-backward');
$('#toggleSidebar').addClass('fa-forward');
return sidebar(1);
}
})
css:
#toggleSidebar {
position:fixed;
display:block;
left:0;
top:45px;
color:#779DD7;
padding:2px 4px;
}
hide {
display: none;
}
show {
display: inherit;
}
html:
<div class="container">
<div class="row">
<div class="col-md-3 hide" id="sidebar1">
<div id="sidebar" class="bs-sidebar nav bs-sidenav pre-scrollable" role="complementary">
Toc goes here.
</div>
</div>
<div class="col-md-12" id="content">
Main text goes here.
</div>
</div>
<a id="toggleSidebar" href="#toggleSidebar1" class="fa fa-forward"</a>
</div>
Edit:
Off canvas is not what I need: it doesn't conserve the horizonatal space, it shifts the div to the right, and the div gets out of the screen. Chanding col-md-9
to col-md-12
and back -- is the best thing I can think of for a problem at hand. This should be simple javascript, which I'm not good at.