| 55 | `, |
| 56 | }) |
| 57 | export class AppComponent { |
| 58 | scrollElement = viewChild<ElementRef<HTMLDivElement>>('scrollElement') |
| 59 | |
| 60 | scrollingTime = signal(0) |
| 61 | |
| 62 | virtualizer = injectVirtualizer(() => ({ |
| 63 | scrollElement: this.scrollElement(), |
| 64 | count: 10000, |
| 65 | estimateSize: () => 35, |
| 66 | overscan: 5, |
| 67 | scrollToFn: (offset, options, instance) => { |
| 68 | const duration = 1000 |
| 69 | const start = this.scrollElement()!.nativeElement.scrollTop |
| 70 | const startTime = Date.now() |
| 71 | this.scrollingTime.set(startTime) |
| 72 | |
| 73 | const run = () => { |
| 74 | if (this.scrollingTime() !== startTime) return |
| 75 | const now = Date.now() |
| 76 | const elapsed = now - startTime |
| 77 | const progress = easeInOutQuint(Math.min(elapsed / duration, 1)) |
| 78 | const interpolated = start + (offset - start) * progress |
| 79 | |
| 80 | if (elapsed < duration) { |
| 81 | elementScroll(interpolated, options, instance) |
| 82 | requestAnimationFrame(run) |
| 83 | } else { |
| 84 | elementScroll(interpolated, options, instance) |
| 85 | } |
| 86 | } |
| 87 | requestAnimationFrame(run) |
| 88 | }, |
| 89 | })) |
| 90 | |
| 91 | randomIndex = signal(Math.floor(Math.random() * 10000)) |
| 92 | |
| 93 | scrollToRandomIndex() { |
| 94 | this.virtualizer.scrollToIndex(this.randomIndex()) |
| 95 | this.randomIndex.set(Math.floor(Math.random() * 10000)) |
| 96 | } |
| 97 | } |
nothing calls this directly
no test coverage detected