To better understand this concept, please refer to the following fiddle: http://jsfiddle.net/abhicodes/LasxP/
The main goal here is to calculate the visible height of the element with the ID #content-wrapper
as the user scrolls. The height of the header (#header
) remains constant and fixed, but the footer height varies across different pages, making it impossible to use the current footer height as a standard measurement.
Even when scrolling to the end of the page where the footer occupies most of the area, we still need to determine the visible portion of #content-wrapper
. In cases where the footer is not visible, subtracting the header height from the viewport height gives us the visible part of the content.
For example, if the viewport height at the bottom of the page is 600px, with the footer taking up 100px and the header 80px, the visible height of #content-wrapper
would be 420px. Conversely, at the top of the page where only the header is present, the visible area of #content-wrapper
would be 520px.
In essence, what we aim to achieve is dynamically determining the visible height of #content-wrapper
for the user during any given scroll based on the scenario presented in the aforementioned fiddle.