Skip to content

Commit 49863b7

Browse files
committed
fix(pat inject): autoload-visible only when in viewport.
Fix autload-visible trigger to only load the injection if the element is in the viewport. As before, this check is done after 100ms. This prevents loading items when we quickly scoll across them, like with href-section-jumps.
1 parent eac7bec commit 49863b7

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

src/pat/inject/inject.js

+9-11
Original file line numberDiff line numberDiff line change
@@ -992,24 +992,22 @@ const inject = {
992992
if (!$el.is(":visible")) {
993993
return false;
994994
}
995+
if (!utils.elementInViewport($el[0])) {
996+
return false;
997+
}
995998
// check if the target element still exists. Otherwise halt and catch fire
996999
const target = (
9971000
$el.data("pat-inject")[0].target || cfgs[0].defaultSelector
9981001
).replace(/::element/, "");
9991002
if (target && target !== "self" && $(target).length === 0) {
10001003
return false;
10011004
}
1002-
const reltop =
1003-
$el.safeOffset().top - $scrollable.safeOffset().top - 1000,
1004-
doTrigger = reltop <= $scrollable.innerHeight();
1005-
if (doTrigger) {
1006-
// checkVisibility was possibly installed as a scroll
1007-
// handler and has now served its purpose -> remove
1008-
$($scrollable[0]).off("scroll", checkVisibility);
1009-
$(window).off("resize.pat-autoload", checkVisibility);
1010-
return trigger();
1011-
}
1012-
return false;
1005+
1006+
// checkVisibility was possibly installed as a scroll
1007+
// handler and has now served its purpose -> remove
1008+
$($scrollable[0]).off("scroll", checkVisibility);
1009+
$(window).off("resize.pat-autoload", checkVisibility);
1010+
return trigger();
10131011
}, 100);
10141012
if (checkVisibility()) {
10151013
return true;

0 commit comments

Comments
 (0)