Closed ghenry22 closed 1 year ago
The component responds to native HTML scroll events, so to update the scroll position you can simply scroll the container element itself. For example:
//MyComponent.ts:
import { ElementRef } from ‘@angular/core’;
class MyComponent {
@ViewChild("virtualScroll", { read: ElementRef })
public scrollContainer: ElementRef<HTMLElement>;
…
public scrollTo(yPos: number) {
// li-virtual-scroll will automatically re-render based on the new scroll position
this.scrollContainer.nativeElement.scrollTo(0, yPos);
}
}
<!-- MyComponent.html -->
<li-virtual-scroll #virtualScroll [items]="items">
…
</li-virtual-scroll>
Got it, will give that a try thanks!
The scrollPosition Value is read-only currently.
This means we cannot implement something like a simple scroll to top functionality.
Proposed Solution Implement a "ScrollTo" function which can accept an item number in the virtual list. Implement a "ScrollToXY" function which can accept x/y co-ordinates to set the scrollPosition directly ie scrollToXY({x: 0, y: 0})