Skip to content

Commit f37bc99

Browse files
committed
maint(pat scroll): Use the new scrolling helpers from core.dom.
This fixes also the scrolling position from the previous release which would have been wrong for many cases where the scrolling target is within a positioned element.
1 parent 89d3ef3 commit f37bc99

File tree

1 file changed

+12
-31
lines changed

1 file changed

+12
-31
lines changed

src/pat/scroll/scroll.js

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -69,36 +69,6 @@ class Pattern extends BasePattern {
6969
window
7070
);
7171

72-
const scroll_options = { behavior: "auto" }; // Set the behavior in CSS.
73-
if (this.options.selector === "top") {
74-
// Just scroll up or left, period.
75-
scroll_options[this.options.direction] = 0;
76-
} else if (this.options.selector === "bottom") {
77-
// Just scroll down or right, period.
78-
if (this.options.direction === "top") {
79-
scroll_options.top = (
80-
scroll_container === window ? document.body : scroll_container
81-
).scrollHeight;
82-
} else {
83-
scroll_options.left = (
84-
scroll_container === window ? document.body : scroll_container
85-
).scrollWidth;
86-
}
87-
} else if (this.options.direction === "top") {
88-
scroll_options.top = target.offsetTop;
89-
} else if (this.options.direction === "left") {
90-
scroll_options.left = target.offsetLeft;
91-
}
92-
93-
if (typeof scroll_options.top !== "undefined") {
94-
scroll_options.top -= this.options.offset;
95-
}
96-
if (typeof scroll_options.left !== "undefined") {
97-
scroll_options.left -= this.options.offset;
98-
}
99-
100-
log.debug("scroll_options: ", scroll_options);
101-
10272
// Set/remove classes on beginning and end of scroll
10373
this.el.classList.add("pat-scroll-animated");
10474
const debounced_scroll_end = utils.debounce(() => {
@@ -115,7 +85,18 @@ class Pattern extends BasePattern {
11585
debounced_scroll_end();
11686

11787
// now scroll
118-
scroll_container.scrollTo(scroll_options);
88+
if (this.options.selector === "top") {
89+
dom.scroll_to_top(scroll_container, this.options.offset);
90+
} else if (this.options.selector === "bottom") {
91+
dom.scroll_to_bottom(scroll_container, this.options.offset);
92+
} else {
93+
dom.scroll_to_element(
94+
target,
95+
scroll_container,
96+
this.options.offset,
97+
this.options.direction
98+
);
99+
}
119100
}
120101
}
121102

0 commit comments

Comments
 (0)