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

Support scrollableArea as an element #268

Merged
merged 1 commit into from
Mar 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ We utilize pooling techniques to reuse Intersection Observers and rAF observers
* [`didScroll(up,down,left,right)`](#didscrollupdownleftright)
* [`viewportEntered`](#viewportentered)
* [`viewportExited`](#viewportexited)
* [**IntersectionObserver**'s Browser Support](#intersectionobservers-browser-support)
* [**IntersectionObserver**'s Browser Support](#intersectionobservers-browser-supportscrollableArea)
+ [Out of the box](#out-of-the-box)
* [Running](#running)
* [Running Tests](#running-tests)
Expand Down
5 changes: 4 additions & 1 deletion addon/-private/raf-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ export function startRAF(
addRAF, // bound function from service to add elementId to raf pool
removeRAF // bound function from service to remove elementId to raf pool
) {
const domScrollableArea = scrollableArea ? document.querySelector(scrollableArea) : undefined;
const domScrollableArea =
typeof scrollableArea === 'string' && scrollableArea ? document.querySelector(scrollableArea)
: scrollableArea instanceof HTMLElement ? scrollableArea
: undefined;

const height = domScrollableArea
? domScrollableArea.offsetHeight + domScrollableArea.getBoundingClientRect().top
Expand Down
2 changes: 1 addition & 1 deletion addon/services/in-viewport.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export default class InViewport extends Service {

buildObserverOptions({ intersectionThreshold = 0, scrollableArea = null, viewportTolerance = {} }) {
const domScrollableArea =
typeof scrollableArea === 'string' ? document.querySelector(scrollableArea)
typeof scrollableArea === 'string' && scrollableArea ? document.querySelector(scrollableArea)
: scrollableArea instanceof HTMLElement ? scrollableArea
: undefined;

Expand Down