I have two columns, #photos
and #text
. My #photos
column is longer and logically holds some images. When I scroll the page, I like the #photos
column to scroll faster than the #text
column, so that both columns align at the bottom.
I use jQuery's $(window).scroll()
to update the #photos
column:
$("#photos").css("top", Math.round(targetY));
How do I calculate targetY?
I know it probably has something to do with $(document).height()
, $("#photos").height()
and $(window).scrollTop()
, but I can't figure out the formula.
Without a bit more code to look at, I can't really suggest changes to make directly to your code but I've managed to mock up a working version of what you're perhaps looking for with the following jsFiddle.
I've also broken down the equation into parts to make it easier to see what's going on.
So as you scroll the
text
div, thephotos
div scrolls at the same ratio depending on the height of the two containers.JavaScript:
HTML:
Hope it helps you solve your problem.