There's a code snippet that enables the header to become unfixed when a specific div reaches the top of the screen and then scrolls with the rest of the content.
While this solution works perfectly, I encountered a problem where the calculations for "const targetTopPos = targetEl.getBoundingClientRect().top" are incorrect when the page is already scrolled. I'm unsure why this issue is happening.
Another issue arises when the page is refreshed while scrolled down, causing the header to remain fixed until you scroll again.
Below is the code snippet:
I have included a console log for "targetTopPos" to help identify the issue.