object:scrollToPosition()

Type Function
Library widget.*
Revision Release 2024.3703
Keywords widget, scroll view, ScrollViewWidget, scrollToPosition
See also object:scrollTo()
widget.newScrollView()
ScrollViewWidget

Overview

Makes a ScrollViewWidget scroll to a specific x or y position.

Syntax

object:scrollToPosition( options )

This function takes a single argument, options, which is a table that accepts the following parameters:

x (optional)

Number. The x position to scroll to. If you only want to scroll vertically, you should omit this parameter.

y (optional)

Number. The y position to scroll to. If you only want to scroll horizontally, you should omit this parameter.

time (optional)

Number. Time in milliseconds to scroll to the specified coordinate(s). For an instantaneous effect (no transition), set this to 0. Default is 400.

onComplete (optional)

Function. An optional function that will be called when the scroll completes.

Example

local function onScrollComplete()
    print( "Scroll complete!" )
end

scrollView:scrollToPosition
{
    x = 100,
    y = -100,
    time = 800,
    onComplete = onScrollComplete
}