Closed MrBushid0 closed 1 month ago
Hi,
The offset setting in the Sticky feature doesn't work as expected when you have different offsets declared in 3 or more breakpoints.
To test:
1- Enable Sticky on some element 2- Define default offset of 200 3- Define an offset for tablet of 300 4- Define an offset for mobile of 50
Result:
On mobile, the element will turn sticky at the offset defined for the tablet breakpoint instead of the one defined on the mobile breakpoint.
Fix:
In sticky.js, getOffset() function, sort the breakpoints before doing a lookup
Change
const foundBreakpoint = breakpoints .filter((b) => b.id !== BASE_BREAKPOINT_ID) .find((b) => matchMedia(b.id));
To
const foundBreakpoint = breakpoints .filter((b) => b.id !== BASE_BREAKPOINT_ID) .sort((a, b) => a.maxWidth - b.maxWidth) .find((b) => matchMedia(b.id));
Thanks!
Thanks for report and suggested fix. This will be addressed in 2.0.
Thanks for the report. This has been addressed in Breakdance 2.0.
Hi,
The offset setting in the Sticky feature doesn't work as expected when you have different offsets declared in 3 or more breakpoints.
To test:
1- Enable Sticky on some element 2- Define default offset of 200 3- Define an offset for tablet of 300 4- Define an offset for mobile of 50
Result:
On mobile, the element will turn sticky at the offset defined for the tablet breakpoint instead of the one defined on the mobile breakpoint.
Fix:
In sticky.js, getOffset() function, sort the breakpoints before doing a lookup
Change
const foundBreakpoint = breakpoints .filter((b) => b.id !== BASE_BREAKPOINT_ID) .find((b) => matchMedia(b.id));
To
const foundBreakpoint = breakpoints .filter((b) => b.id !== BASE_BREAKPOINT_ID) .sort((a, b) => a.maxWidth - b.maxWidth) .find((b) => matchMedia(b.id));
Thanks!