I have a .job-banner
div
in the middle of my page with CSS position:sticky
and javascript watcher adding a "sticky" class whenever scrolling past it. Due to the style guide I need to apply different spacing and font size within .job-banner
when it’s sticky. I found that my implementation often glitches when scrolling and I’m not sure how to fix it.
Here is a simplified Codepen to demonstrate: https://codepen.io/anzuj/pen/GRzqPGP
Any tips would be welcome!
2
Answers
To fix your glitching, you’re going to have to make several changes.
The first thing you need to do is not have the banner sticky unless the .sticky class is added. The reason this is important is it will allow you to scroll past the top of the banner.
Revised CSS:
But that won’t do much unless you make some changes to the JavaScript too:
What this does is it allows you to scroll 70 pixels past the banner, allowing you to skip the glitching effect.
It jumps because you resize it.
Use
position: fixed;
and account for resizing. This can be done by giving the height to the parent. Somehow: