From 253ac4ae4a97fa92e0e9faf1763407e3876dfbde Mon Sep 17 00:00:00 2001 From: Johannes Raggam Date: Mon, 1 Sep 2025 12:06:41 +0200 Subject: [PATCH 1/2] fix(pat-scroll): Fix issue where no scroll target can be found. Use document.body instead. --- src/pat/scroll/scroll.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/pat/scroll/scroll.js b/src/pat/scroll/scroll.js index 7e8c248ab..c5d70f103 100644 --- a/src/pat/scroll/scroll.js +++ b/src/pat/scroll/scroll.js @@ -52,12 +52,15 @@ class Pattern extends BasePattern { await utils.timeout(this.options.delay); } - const target = this.get_target(); - const scroll_container = dom.find_scroll_container( - target.parentElement, - this.options.direction === "top" ? "y" : "x", - window - ); + const target = this.get_target() || document.body; + const scroll_container = + target === document.body + ? document.body + : dom.find_scroll_container( + target.parentElement, + this.options.direction === "top" ? "y" : "x", + window + ); // Set/remove classes on beginning and end of scroll this.el.classList.add("pat-scroll-animated"); From ed8e9419e1c43b6aa9398d365932175b3c79d4a0 Mon Sep 17 00:00:00 2001 From: Johannes Raggam Date: Mon, 1 Sep 2025 12:30:45 +0200 Subject: [PATCH 2/2] fix(core dom): Don't break when elements given to get_relative_position and scroll_to_element are window or document and as such no real DOM elements. Use document.body instead. --- src/core/dom.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/core/dom.js b/src/core/dom.js index 01c9ef8b8..053d81e06 100644 --- a/src/core/dom.js +++ b/src/core/dom.js @@ -364,9 +364,12 @@ const get_relative_position = (el, reference_el = document.body) => { // the relative position of the target. // In case of a scroll container of window, we do not have // getBoundingClientRect method, so get the body instead. - if (reference_el === window) { + if (reference_el === window || document) { reference_el = document.body; } + if (el === window || document) { + el = document.body; + } // Calculate absolute [ยน] position difference between // scroll_container and scroll_target. @@ -407,6 +410,14 @@ const get_relative_position = (el, reference_el = document.body) => { * @param {string} [direction="top"] - The direction to scroll to. Can be either "top", "left" or "both". */ const scroll_to_element = (el, scroll_container, offset = 0, direction = "top") => { + // Normalize el and scroll_container + if (el === window || document) { + el = document.body; + } + if (scroll_container === window || document) { + scroll_container = document.body; + } + // Get the position of the element relative to the scroll container. const position = get_relative_position(el, scroll_container);