MCPcopy Index your code
hub / github.com/TanStack/virtual / AppComponent

Class AppComponent

examples/angular/smooth-scroll/src/app/app.component.ts:57–97  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

55 `,
56})
57export 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}

Callers

nothing calls this directly

Calls 1

injectVirtualizerFunction · 0.90

Tested by

no test coverage detected