Skip to content

Commit

Permalink
fix: Emit ScrollBox scroll event when dragging content
Browse files Browse the repository at this point in the history
  • Loading branch information
CyberDex committed Aug 22, 2024
1 parent 6dc8b9c commit c8bbc05
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/ScrollBox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ export class ScrollBox extends Container
{
if (!this.isDragging) return;

const isVertical: boolean = this.options.type !== 'horizontal';
const touchPoint = this.worldTransform.applyInverse(e.global);

if (this.dragStarTouchPoint)
Expand Down Expand Up @@ -427,6 +428,8 @@ export class ScrollBox extends Container

this.pressedChild = null;
}

this.onScroll?.emit(isVertical ? this.scrollY : this.scrollX);
});

document.addEventListener('wheel', this.onMouseScrollBinding, true);
Expand Down Expand Up @@ -565,9 +568,6 @@ export class ScrollBox extends Container

protected onMouseScroll(event: WheelEvent): void
{
const isVertical: boolean = this.options.type !== 'horizontal';
const oldScrollPos = isVertical ? this.scrollY : this.scrollX;

if (!this.isOver && !this.options.globalScroll) return;

this.renderAllItems();
Expand All @@ -592,6 +592,8 @@ export class ScrollBox extends Container

this._trackpad.xAxis.value = Math.min(max, Math.max(min, targetPos));
}

this.onScroll?.emit(this._trackpad.xAxis.value);
}
else if (typeof event.deltaY !== 'undefined')
{
Expand All @@ -608,16 +610,11 @@ export class ScrollBox extends Container

this._trackpad.yAxis.value = Math.min(max, Math.max(min, targetPos));
}

this.onScroll?.emit(this._trackpad.yAxis.value);
}

this.stopRenderHiddenItems();

const newScrollPos = isVertical ? this.scrollY : this.scrollX;

if (newScrollPos !== oldScrollPos)
{
this.onScroll?.emit(newScrollPos);
}
}

/** Makes it scroll down to the last element. */
Expand Down

0 comments on commit c8bbc05

Please sign in to comment.