Reputation: 331
There are dwo divs #leftPane and #rightPane. #leftPane has position relative and browser set scrollbar acording to its height, meanwhile #rightPane has position: fixed and I add top: -value to it while scrolling, so we 'scroll' secont div with different speed. What I want to achieve is get something like scrollSpeedModifier according to 1. browser window height, 2 leftPane content height and 3 rightPane content height (2,3 content height might be different each time).
So while scrolling #leftPane - if content of #rightPane is bigger than #leftPane its top value grow faster than normal scrolling, but when #rightPane content height is smaller than #leftPanes top value grow slower than normal scroling.
This is the way I count the speed right now:
ar scrollSpeed = (rightPaneHeight) / browserHeight;
but it's wrong, sometimes we get to the middle of the #rightPane and when we change the 'browser' size (jfiddle window size) we might get till the end of #rightPane.
This is the code I end up so far:
Upvotes: 3
Views: 2200
Reputation: 331
ok fixed, http://jsfiddle.net/bVfcX/21/
the right algorithm is:
-$(window).scrollTop() * ((browserHeight - rightPaneHeight) / (browserHeight - leftPaneHeight));
Upvotes: 1