Skip to content

Commit

Permalink
Feat: Add scroll event listener to ScrollBox (#187)
Browse files Browse the repository at this point in the history
  • Loading branch information
CyberDex authored Jul 30, 2024
1 parent 2faea73 commit 8804bf4
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/ScrollBox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export class ScrollBox extends Container
protected lastScrollY!: number | null;
protected proximityCheckFrameCounter = 0;
public onProximityChange = new Signal<(data: ProximityEventData) => void>();
public onScroll: Signal<(value: number) => void> = new Signal();

/**
* @param options
Expand Down Expand Up @@ -567,6 +568,9 @@ 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 Down Expand Up @@ -610,6 +614,13 @@ export class ScrollBox extends Container
}

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 Expand Up @@ -872,4 +883,12 @@ export class ScrollBox extends Container
item.children.forEach((child) => this.revertClick(child));
}
}

get scrollHeight(): number {
return this.list.height;
}

get scrollWidth(): number {
return this.list.width;
}
}

0 comments on commit 8804bf4

Please sign in to comment.