views:

52

answers:

2

I have a page with a header, footer, and middle area. The middle is 3 equal columns, each 33% width.

When a column is clicked, I'd like for that column to climb above the 2 other columns and get a width of 100%, and the 2 columns to redistribute to 50-50.

  • Is this sort of thing possible (and reliable) with jquery, or is it too much of a hassle?
  • Can it be done with animations?
  • Any examples
+7  A: 

Yes it can be done:

$("#column1").css("width", "100%");
$("#column2, #column3").css("width", "50%");

And to move the column to the top, you can do something like this:

$(column).parent().prepend(column);

I've put together an example here on jsFiddle for how to do it on the click of the div.

jQuery is probably the most reliable way to do it as it's written to be cross browser compatible.

Take a look at the document for the css method here.

GenericTypeTea
You might want to float those columns and clear the top one so it appears on the top.
ILMV
@ILMV - I know, not done yet! Just writing the fiddle.
GenericTypeTea
Changing width on-the-go won't work for internet explorer. Not sure about IE8, but 6 and 7 won't work. Recently tested it.
Tom
@GenericTypeTea :-) Saweeeeeeeeeeeet
ILMV
I didn't mean that you can't resize them at all. I recently was working on an interesting login-panel which involved width changing and everything. When using jQuery for changing width of the element on the go, it didn't work for Internet Explorer 6 and 7, can't remember about Internet Explorer 8 tho'. Of course you can resize divs as you wish through static `css` values. But I'm not sure if it wasn't caused because of my static `css`.
Tom
@GenericTypeTea: http://jsfiddle.net/g7BsA/ <- here you have an example, since the element is positioned absolutely it isn't resized in IE6, IE7. Works in IE8 and every other modern browsers.
Tom
@Tom - Weirdly enough, it works in IE7 if you give it a background. http://jsfiddle.net/g7BsA/2/
GenericTypeTea
@GenericTypeTea: Now that's even more interesting. :O
Tom
+2  A: 

http://docs.jquery.com/Tutorials:Live_Examples_of_jQuery

Check out example B as I think that's what you're looking for. I don't have a lot of experience myself with jQuery so unfortunately this is the best advice I'm going to be able to give you.

KSwift87