tags:

views:

37

answers:

1

I've got 4 panels, and I have a checklist at the top which controls which panels you want to view. How would I set it up so that if they uncheck one of the panels, then the rest will reposition. A bit vague, so:

    ___   ___
   | 1 | | 2 |
   |___| |___|
    ___   ___
   | 3 | | 4 |
   |___| |___|

So if they uncheck 2 and 3, I would like 4 to be position next to 1

    ___   ___
   | 1 | | 4 |
   |___| |___|

And if they unchecked just 3, then 4 would go to the 3's position. These panels would also be centered on the page, but if the something like the 3 is unchecked, I want the fourth panel to be left aligned with the first panel, and not centered between them. So like this:

    ___   ___
   | 1 | | 2 |
   |___| |___|
    ___
   | 4 |
   |___|

And not this:

    ___   ___
   | 1 | | 2 |
   |___| |___|
       ___
      | 4 |
      |___|
+3  A: 

Placing the 4 panels (same fixed size) within a fixed container which is at least twice the width of each panel but less than 3 times. Float the panel. Example as follows:

CSS:

#panels {
    width: 400px;
}
.panel {
    float: left;
    width: 190px;
    height: 100px;
    border: solid 1px #f00;

}

JS:

$(function(){
    $("div input[type='checkbox']").attr('checked',true);
    $("div input[type='checkbox']").change(function() {
            if($(this).attr('checked'))
                $('#' + $(this).val()).show();
            else
                $('#' + $(this).val()).hide();
        }
    );
});

HTML:

<div>
<label for="p1"><input type="checkbox" value="panel1" />1</label>
<label for="p2"><input type="checkbox" value="panel2" />2</label>
<label for="p3"><input type="checkbox" value="panel3" />3</label>
<label for="p4"><input type="checkbox" value="panel4" />4</label>
</div>
<div id="panels">
<div class="panel" id="panel1">1</div>
<div class="panel" id="panel2">2</div>
<div class="panel" id="panel3">3</div>
<div class="panel" id="panel4">4</div>
</div>
o.k.w
Ah okay thanks, I thought I tried this already and had problems, but I got it working now. Thanks a lot.
Justen
No problem. Glad you got it to work :)
o.k.w
Ooo one thing I just found, the panels are different heights and that causes alignment issues. Like P1 is 600px, and P2 is 300px and P3 is 400px. So if I hide all panels or something, then show 1, 2, then 3, the 3rd panel get's hooked on the lower end of P1
Justen
Well nvm to that. If someone else comes along and has the same problem, just put panels in a container div with the same height
Justen
Yea, you just got to fiddle around with the sizes.
o.k.w