strongBAD
strongBAD

Reputation: 331

jQuery algorithm scrolling speed

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:

http://jsfiddle.net/bVfcX/15/

Upvotes: 3

Views: 2200

Answers (2)

strongBAD
strongBAD

Reputation: 331

ok fixed, http://jsfiddle.net/bVfcX/21/

the right algorithm is:

-$(window).scrollTop() * ((browserHeight - rightPaneHeight) / (browserHeight - leftPaneHeight));

Upvotes: 1

mehdi
mehdi

Reputation: 1755

see this Demo

  1. var doc = $(window); // for get height of document

  2. doc.scrollTop is a function use doc.scrollTop()

give it a try.

Upvotes: 0

Related Questions