0

I've looked everywhere but I couldn't find the right solution

The sidebar is long but there's still white space when I get to the end because it's not the length of the content. So, I was thinking maybe having it 'fixed' using jquery but the thing is, is that it's still a long sidebar.. So is there a way for me to have the sidebar scroll gradually as I scroll so that it reaches the bottom of the sidebar the same time it I reach the footer?

I thought about something maybe like "(0, sidebarTop - scrollTop)" with 'sidebartop' being the position ('top' increases as you scroll so it pushes the sidebar down) but it not working right.. it's actually pushing it up

I'm a bit sleep deprived and I may not be thinking about it clear at the moment but I need to figure this out for a client due saturday..

You see how the sidebar long? (shorten your browser) -- I would like it so that the sidebar will move gradually down with the content just like this

4

1 に答える 1

1

少し余分な計算が必要です: http://jsfiddle.net/VEsdu/317/

scrolled = Math.min(1, (scrollTop - sidebarTop)/(ch - wh));
topPosition += scrolled * (ch - sh);

最初の行では、ビューポート内のコンテンツのどの部分を取得しますか。ビューポート上部のコンテンツの上部は 0、ビューポート下部のコンテンツの下部は 1 です。2 行目で、コンテンツとサイドバーの高さの差に比例してサイドバーに余白を追加します。

これがサイドバー/コンテンツよりも高いビューポートで機能するかどうか、またはウィンドウのサイズ変更後に機能するかどうかはわかりません。その場合を確認する必要があります。

于 2013-01-11T01:14:39.537 に答える