-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle zero-area and display: none cases
Attempts to satsify the spec: https://www.w3.org/TR/intersection-observer/#update-intersection-observations-algo isIntersecting, non-zero area, and display:nonen are all related, so fixing in one swoop. Fixes: #93 #73 Related issues: w3c/IntersectionObserver#69 w3c/IntersectionObserver#222
- Loading branch information
Showing
10 changed files
with
656 additions
and
522 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,3 @@ | ||
export function entrySatisfiesRatio(entry: IntersectionObserverEntry, threshold: number) { | ||
let { boundingClientRect, intersectionRatio } = entry; | ||
|
||
// Edge case where item has no actual area | ||
if (boundingClientRect.width === 0 || boundingClientRect.height === 0) { | ||
let { boundingClientRect, intersectionRect } = entry; | ||
return ( | ||
boundingClientRect.left === intersectionRect.left && | ||
boundingClientRect.top === intersectionRect.top && | ||
intersectionRect.width >= 0 && | ||
intersectionRect.height >= 0 | ||
); | ||
} else { | ||
return intersectionRatio > threshold || (intersectionRatio === 1 && threshold === 1); | ||
} | ||
export function calculateIsIntersecting({ intersectionRect }: { intersectionRect: ClientRect }) { | ||
return intersectionRect.width > 0 || intersectionRect.height > 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.