Change position with scroll?

I have a “sidecontent” area on a site. It’s position:fixed on the lefthand side.

There is a “scrolled-up” header with a height of 150px, and a “scrolled down” header with a height of 80px.

This issue is that between the two headers, a gap is created between the bottom of the header and the top of the sidecontent.

Is there a good way to fix this?

The best I can come up with is to set a variable of the current scroll position and base the sidecontents position on that, maybe? I’m a JS plebian, so forgive my ignorance.

When the scrolled down header is in effect modify the JS to toggle a class to the sidebar and use that class in css to set the different top position for the sidebar. (Assuming you can rely on a fixed height of the header and it doesn’t change height when resized etc.)

The “scrolled-down” header is a different height than the “scrolled-up” header.

The “scrolled-up” header has an ad slot and a sub-header, so it’s significantly taller than the “scrolled-down” header.

I tried the “toggling” method that you mentioned, and it created a gap during the transition between up/down.

Do you have a link to the page in question so we can see what you have at present?

There are many ways that these headers can be implemented and some only appear when you stop scrolling and some only appear when you start scrolling back up.

I’m guessing that your large header scrolls away when you start scrolling down the page and a smaller sticky header slides down instead. Therefore you want the top of your fixed side navigation to move up and fill the extra space when the smaller header appears. The easiest way would be to add class as I suggest and move the top of the sidebar when the smaller header is in place.

Here’s a quickly adjusted old demo using the class swap as I suggested.

If instead you wanted the fixed sidebar to constantly monitor the header height then that would be more complex to code (and time for a js guru to step in :slight_smile: ) .

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.