Skip to content

Commit 73c01b0

Browse files
committed
Don't call things invisible if they're just scrolled off the page, either horizontally or vertically.
Relevant to #232 ever so slightly.
1 parent 7db82e6 commit 73c01b0

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

fathom/utilsForFrontend.mjs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,10 @@ export function sigmoid(x) {
462462
/**
463463
* Return whether an element is practically visible, considering things like 0
464464
* size or opacity, ``visibility: hidden`` and ``overflow: hidden``.
465+
*
466+
* Merely being scrolled off the page in either horizontally or vertically
467+
* doesn't count as invisible; the result of this function is meant to be
468+
* independent of viewport size.
465469
*/
466470
export function isVisible(fnodeOrElement) {
467471
// This could be 5x more efficient if https://github.com/w3c/csswg-drafts/issues/4122 happens.
@@ -475,11 +479,9 @@ export function isVisible(fnodeOrElement) {
475479
if (elementStyle.visibility === 'hidden') {
476480
return false;
477481
}
478-
// Check if the element is off-screen:
479-
const frame = element.ownerDocument.defaultView;
482+
// Check if the element is irrevocably off-screen:
480483
if (elementRect.x + elementRect.width < 0 ||
481-
elementRect.y + elementRect.height < 0 ||
482-
elementRect.x > frame.innerWidth || elementRect.y > frame.innerHeight
484+
elementRect.y + elementRect.height < 0
483485
) {
484486
return false;
485487
}

0 commit comments

Comments
 (0)