News for hackers. Stuff that matters.
Re:Ask HN: How do you create a "limited fixed div"? by qhoxie on Saturday January 10, 2009 @03:45AM (#427815)
I did this in jQuery at one time. Hopefully this is helpful.

  $(window).scroll(function() {
    var offsetTop = $(window).scrollTop();
    $("#target").css({top: offsetTop});
  });
To explain, whenever the viewport is scrolled, the offset of the viewport to the top of the page is set (offsetTop). Then the #target element is moved to follow the viewport. That will give a fixed effect, so what you need to do is set the max offsetTop to (max depth - #target height).

Note: Dimension type calculations vary widely among browsers, so using a library like jQuery dimensions is quite helpful.

Re:Ask HN: How do you create a "limited fixed div"? by davidjeffries on Saturday January 10, 2009 @04:46AM (#427841)
+1 for jQuery dimensions. That plugin is a godsend for doing things like this.
Re:Ask HN: How do you create a "limited fixed div"? by sam_in_nyc on Saturday January 10, 2009 @04:52AM (#427846)
scrollTop(), offset(), and the like are built in to the latest jQuery.

I love jQuery.

Re:Ask HN: How do you create a "limited fixed div"? by unalone on Saturday January 10, 2009 @08:14PM (#428618)
Excellent! jQuery's what I've been using already. Thanks a ton!