mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
fix: initial scroll must always be multiple of content offset
This commit is contained in:
@@ -42,11 +42,14 @@ export class SegmentView implements ComponentInterface {
|
||||
|
||||
@Listen('scroll')
|
||||
handleScroll(ev: Event) {
|
||||
const { initialScrollLeft, previousScrollLeft } = this;
|
||||
const { previousScrollLeft } = this;
|
||||
const { scrollLeft, offsetWidth } = ev.target as HTMLElement;
|
||||
|
||||
// Set initial scroll position if it's undefined
|
||||
this.initialScrollLeft = initialScrollLeft ?? scrollLeft;
|
||||
// Must be a multiple of the offset width
|
||||
if (this.initialScrollLeft === undefined) {
|
||||
this.initialScrollLeft = Math.round(scrollLeft / offsetWidth) * offsetWidth;
|
||||
}
|
||||
|
||||
// Determine the scroll direction based on the previous scroll position
|
||||
const scrollDirection = scrollLeft > previousScrollLeft ? 'right' : 'left';
|
||||
|
||||
Reference in New Issue
Block a user