views:

216

answers:

1

Hi,

I have a simple 3 column site - left, center and right. The center column is where the main text content goes and is generally much longer than the left or right content.

before I write one, is there a JQuery plugin to keep my left and right column content in view when the user scrolls the window? i.e. they stick to 10px below the top of the screen when scrolling so they're always in view. but when the user scrolls right up to the top, they sit in their proper places.

An example page is here: http://www.flowmtb.com/morzine/

Obviously if the browser window is shorter than the left or right content, they shouldn't move, otherwise the user will never see what's out of sight!

Cheers, Guy

+1  A: 

You don't need jQuery for this. Check out position: fixed in CSS. But you can use jQuery to detect the size of the browser window, so you can set position: absolute; if it's too small.

Update: I made an example page. The important code is this:

function colfix(column) {
  if($(window).height() + 20 < $(column).height()) {
    $(column).css("position", "absolute");
  }else{
    $(column).css("position", "fixed");
  }
}

$(document).ready(function() {
  colfix("#two");
})

$(window).resize(function() {
  colfix("#two");
});
Emil Vikström
+1 for that, and here's the hack to make it work for ie6: http://www.howtocreate.co.uk/fixedPosition.html (altho the author calls that 'counter productive')
David Hedlund
I guess I was looking for a plugin to do the hard work - should it scroll, make it scroll nicely (animation), etc etc. I can write something to work, but didn't want to re-invent the wheel!
Guy Bowden
Personally, I think those "nice scrolling" elements are just irritating as they steal focus from what's important on the page.
Emil Vikström