Skip to content

Commit 4da8d70

Browse files
committed
fix(pat-bumper): Fix position calculation for sticky elements.
Following the sticky position specification only top, right, bottom and left values are used to compute the position relative to the scrolling container.
1 parent baae37c commit 4da8d70

File tree

1 file changed

+5
-24
lines changed

1 file changed

+5
-24
lines changed

src/pat/bumper/bumper.js

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,12 @@ class Pattern extends BasePattern {
3939
left: 0,
4040
};
4141

42+
// Element dimensions
4243
this.dim_element = {
4344
top: dom.get_css_value(this.el, "top", true),
4445
right: dom.get_css_value(this.el, "right", true),
4546
bottom: dom.get_css_value(this.el, "bottom", true),
4647
left: dom.get_css_value(this.el, "left", true),
47-
margin_top: dom.get_css_value(this.el, "margin-top", true),
48-
margin_bottom: dom.get_css_value(this.el, "margin-bottom", true),
49-
margin_right: dom.get_css_value(this.el, "margin-right", true),
50-
margin_left: dom.get_css_value(this.el, "margin-left", true),
5148
};
5249

5350
this.dim_container_x = this.container_x
@@ -146,26 +143,10 @@ class Pattern extends BasePattern {
146143
_get_element_positions() {
147144
const bounds = this.el.getBoundingClientRect();
148145
return {
149-
top: Math.round(
150-
bounds.top -
151-
this.dim_element.top -
152-
this.dim_element.margin_top // prettier-ignore
153-
),
154-
right: Math.round(
155-
bounds.right +
156-
this.dim_element.right +
157-
this.dim_element.margin_right // prettier-ignore
158-
),
159-
bottom: Math.round(
160-
bounds.bottom +
161-
this.dim_element.bottom +
162-
this.dim_element.margin_bottom // prettier-ignore
163-
),
164-
left: Math.round(
165-
bounds.left -
166-
this.dim_element.left -
167-
this.dim_element.margin_left // prettier-ignore
168-
),
146+
top: Math.round(bounds.top - this.dim_element.top),
147+
right: Math.round(bounds.right + this.dim_element.right),
148+
bottom: Math.round(bounds.bottom + this.dim_element.bottom),
149+
left: Math.round(bounds.left - this.dim_element.left),
169150
};
170151
}
171152

0 commit comments

Comments
 (0)