How do you create a collapsable sidebar using Twitter's bootstrap

后端 未结 2 508
甜味超标
甜味超标 2021-02-09 02:40

I have been trying to create a sidebar that will expand and collapse using Twitter\'s Bootstrap project but I am not able to get it working. I am trying to use their basic cont

2条回答
  •  一生所求
    2021-02-09 02:47

    This is easily achieved… Please see the following Fiddle..

    This is the gist of it, though… Basically, the sidebar get's hidden after one second of inactivity with the mouse. You swap out the content (has sidebar) and container-fluid (no sidebar) for your main block, and hide the sidebar. Easy as that.

    function onInactive(ms, cb){ 
        var wait = setTimeout(cb, ms); 
        document.onmousemove = document.mousedown =
        document.mouseup = document.onkeydown = 
        document.onkeyup = document.focus = 
        function(){
            clearTimeout(wait);
            wait = setTimeout(cb, ms);
    }; }
    var sidebar = $('div.sidebar'); 
    var content = $('div.content');
    $('body').live('mousemove', function(event) {
        sidebar.addClass('sidebar').fadeIn();
        content.addClass('content').removeClass('container-fluid');
    });
    
    onInactive(1000, function(){
        sidebar.fadeOut(300);
        content.removeClass('content').addClass('container-fluid');
    });
    

提交回复
热议问题