Reference home > @af-utils/virtual-core > VirtualScroller

VirtualScroller class

Core framework-agnostic model.

Signature:

declare class VirtualScroller 

Remarks

What it does:

  • stores item sizes and positions;

  • tracks elements resizing;

  • provides performant way to calculate offsets;

  • deals with scrolling to item index or to offset;

  • emits and allows to subscribe to events.

What it doesn’t do:

  • rendering;

  • styling;

  • all other framework-related stuff.

Constructors

Constructor

Modifiers

Description

(constructor)(params)

Constructs a new instance of the VirtualScroller class

Properties

Property

Modifiers

Type

Description

from

readonly

number

Items range start with overscanCount included

horizontal

readonly

boolean

Scroll container orientation.

scrollSize

readonly

number

Sum of all item sizes

sizesHash

readonly

number

Hash of item sizes. Changed when at least one visible item is resized

to

readonly

number

Items range end with overscanCount included

visibleFrom

readonly

VirtualScrollerExactPosition

Returns snapshot of current scroll position.

Methods

Method

Modifiers

Description

attachItem(element, index)

Start observing size of element at index

detachItem(element)

End observing size of element

getIndex(offset)

Get nearest item index for pixel offset;

getOffset(index)

Get pixel offset by item index;

getSize(itemIndex)

Get last cached item size by item index

on(callBack, events)

Subscribe to model events

scrollToIndex(index, smooth, attempts)

Scroll to item index

scrollToOffset(offset, smooth)

Scroll to pixel offset

set(runtimeParams)

Synchronize runtime parameters

setContainer(element)

Informs model about items container element. Usually not needed.

setItemCount(itemCount)

Notify model about items quantity change

setScroller(element)

Informs model about scrollable element.

setStickyFooter(element)

Start observing size of sticky footer element. Observing is finished if element is null.

setStickyHeader(element)

Start observing size of sticky header element. Observing is finished if element is null.

updateScrollerOffset()

Recalculates the offset between scroller element and container element.