Skip to content

Commit

Permalink
Support scrollableArea as an element (#210)
Browse files Browse the repository at this point in the history
  • Loading branch information
snewcomer authored Sep 26, 2019
1 parent 10d67e4 commit 7190d20
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export default Component.extend(InViewportMixin, {
- To get around the above issue and have `didExitViewport` fire, set your `intersectionThreshold` to `[0, 1.0]`. When set to just `1.0`, when the element is 99% visible and still has isIntersecting as true, when the element leaves the viewport, the element isn't applicable to the observer anymore, so the callback isn't called again.
- If your intersectionThreshold is set to 0 you will get notified if the target `didEnterViewport` and `didExitViewport` at the appropriate time.

- `scrollableArea`
- `scrollableArea: string | HTMLElement`

Default: null

Expand Down
5 changes: 4 additions & 1 deletion addon/services/in-viewport.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,10 @@ export default class InViewport extends Service {
}

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

// https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API
// IntersectionObserver takes either a Document Element or null for `root`
Expand Down

0 comments on commit 7190d20

Please sign in to comment.