Search code examples
jquerycsslayoutsidebar

Set Content's Width to 100% when Sidebar is Hidden?


Beforehand, pardon me for my poor English.

Ok so here's a live site I have: http://bleachindonesia.com/forum/

If you notice the little X on the left, it is a toggle to show/hide sidebar. The jQuery is working fine. The only problem is that the content's width won't get wider (to 100%) / won't fill the empty space when I hide the sidebar (the sidebar left an empty space when hidden).

I need the content's width to be 100% when the sidebar is hidden, but retaining its smooth animation. Perhaps like the one in the vBulletin forum.

Here is the jQuery btw:

//<!--
if($.cookie("sidebarpost") == undefined) {
    $.cookie("sidebarpost", "expanded");
}
var state = $.cookie("sidebarpost");
if(state == "collapsed") {
    $('.lside').hide();
            $('.lclose').hide();
            $('.lopen').show();
}

if($.cookie("sidebarpost") == "expanded") {
    $("#left-side").toggle(function(){
      $.cookie("sidebarpost", "collapsed");
      $('.lopen,.lclose').toggle();
      $('.lside').fadeOut().delay(1000);
      $('#content').hide("slide", { direction: "left" }, 2000);
    },function(){
      $.cookie("sidebarpost", "expanded");
      $('.lopen,.lclose').toggle();
      $('#content').show("slide", { direction: "right" }, 2000).delay(1000);
      $('.lside').fadeIn();
    });
} else {
    $("#left-side").toggle(function(){
      $.cookie("sidebarpost", "expanded");
      $('.lopen,.lclose').toggle();
      $('#content').show("slide", { direction: "right" }, 2000).delay(1000);
      $('.lside').fadeIn();
    },function(){
      $.cookie("sidebarpost", "collapsed");
      $('.lopen,.lclose').toggle();
      $('.lside').fadeOut().delay(1000);
      $('#content').hide("slide", { direction: "left" }, 2000);
    });
}
//-->

I know it's kind of bloated, perhaps if there is a way to minimize it, would be very helpful. Can anybody help?


Solution

  • You could just adjust the content width as part of your toggle functions. Something like:

    $('.lside').fadeOut(400, function(){$('#content').width("98%")});
    
    $('.lside').fadeIn(400, function(){$('#content').width("76%")});