There are two DIV elements in question: #page
and #block
:
<div id="page"></div>
<div id="block"></div>
The #block
element has a fixed position and contains long content with the property overflow:hidden
.
The #page
element also contains some content, but its height may be longer or shorter than that of the #block
element.
The goal is to achieve synchronized scrolling between these two elements. Something similar to this:
To synchronize the scroll between the header and footer elements of the #page
and #block
, we need to calculate the speed at which the #block
element scrolls.
This is how I attempted to accomplish this:
- Calculated the height of the
#page
element - Calculated the height of the content within the
#block
element (since it has a fixed height) Calculated the scroll speed of the
#block
element using:$("#block").outerHeight / $("#page").outerHeight
Triggered the
.scrollTop()
of the#block
element
Initially, it worked as intended, with the #block
element scrolling faster than the #page
element. However, towards the end, the #block
element did not fully scroll.
Here is the JsFiddle link demonstrating the issue: http://jsfiddle.net/zur4ik/bQYrf/2/
If anyone can pinpoint what I might be doing wrong, I would greatly appreciate it. Thank you in advance.