Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doesn't work for another container from body. #7

Open
volodymyrmilovanov2022 opened this issue Jan 20, 2025 · 4 comments
Open

Doesn't work for another container from body. #7

volodymyrmilovanov2022 opened this issue Jan 20, 2025 · 4 comments

Comments

@volodymyrmilovanov2022
Copy link

volodymyrmilovanov2022 commented Jan 20, 2025

Hello
I've faced one issue - if we don't put our header in body directly, but in some other container, which has it's own scroll, everything stops working. It is caused by that fact that we listen for window.scroll event and check for window scrollY
Changing
window.addEventListener('scroll', onScroll) to parent.addEventListener('scroll', onScroll)
and
const scrollTopPosition = window.scrollY to const scrollTopPosition = parent.scrollTop
fixed this issue.

What do You think about such improvement? Maybe You can add one more parameter, such as ScrollParent,which will be window by default?

@FilipChalupa
Copy link
Owner

Hello. You are correct. The hiding header is right now limited to window scroll only. I will investigate how hard it will be to respect other scroll parents but I expect some challenges. I will test the code you suggested first. Thank you.

@FilipChalupa
Copy link
Owner

Do you have by any chance a small example I can test the new feature on? I'm not exactly sure what you are trying to achive. Part of the hiding-header relies on position: sticky which may not even be possible to recreated in nested scroll container but it depends.

@volodymyrmilovanov2022
Copy link
Author

volodymyrmilovanov2022 commented Jan 22, 2025

https://stackblitz.com/edit/vitejs-vite-ky42v2wk
Here i can see, that my solution is also buggy. It is located in hh.ts file. Don't know why, but in my project it works. As far as I see)

@FilipChalupa
Copy link
Owner

Thank you very much. It is very helpful. Now I understand the problem better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants