-
Notifications
You must be signed in to change notification settings - Fork 201
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
IntersectionObserver at 1/3 screen #567
IntersectionObserver at 1/3 screen #567
Conversation
Is it not possible to base it on the height of the table of contents div? |
It should be possible -- adding elements to onScreenElements only if |
But I think that you'd then need to trigger the callback on a scroll event rather than using intersectionobserver right? |
IIUC, the callback is triggered as you scroll -- https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API#result? |
Oh, and we also wanna be checking whether the event.target's bottom is higher than the bd-toc's top? |
Hmmm I should read up on that more...i had thought it only triggers the callback when the target element intersects with the root for the first time, but maybe i am mis remembering! That would indeed be a nicer fix here |
I could very well be wrong -- I've only skimmed the page. If it only triggers on the edges, we can still probably handle this by keeping a list of "things on screen" using IntersectionObserver and checking only those margin items to see if they would collide with bd-toc (w/ a scroll handler that has a debounce + once-per-n-milliseconds throttle). |
I spent a little while looking at this, and I do think what @pradyunsg suggests is possible, though I am not sure it is worth the penalty we'd pay in complexity. There are two ways that we could ensure that we only hide the TOC when it intersects with margin content:
In both cases we'd use the old-fashioned way of "getClientBoundingRect()" and do a manual check for their intersection. However, I'm still inclined to just go with the "1/3 up the page" approach here because it would be much simpler, and I don't know that it would be that big of a deal if the toc didn't quite hide early enough. I guess the things we're trying to avoid here are:
I think that by making the "hiding" action only trigger 1/3 of the way up the page:
Do others agree w/ that tradeoff of complexity and UX? 🤔 |
I'm going to merge this one in as an iterative improvement - we can track making an update to do a more proper "intersection check" in another issue to figure out the costs / benefits. |
This adjusts our IntersectionObserver so that the Table of Contents section hides itself when margin content is 33% up from the bottom of the screen, rather than as soon as it shows up on the screen at all.
This should hopefully be a nice balance between "it doesn't hide soon enough and so blocks content" and "it hides too aggressively / quickly" as reported in:
I chose 33% as it seemed to be a reasonable point at which a reader might actually want to look at some margin content.
cc @spring-haru - think this is a nice compromise?
closes jupyter-book/jupyter-book#1729