Skip to content

Scroll Snap

Ilia Petrov-Komotskii edited this page Oct 11, 2026 · 3 revisions

Helpers for ScrollRect.

Snap

Moves content so a child is centered in the viewport, shifted by an optional offset (positive moves the child right / up). Unless the ScrollRect movement type is Unrestricted, the content stops at its edges, so the first and last items get as close to the center as the content allows. The result does not depend on the anchors or pivots of the content and the items. Calls Canvas.ForceUpdateCanvases() first and stops the inertia on the snapped axes.

using Mane.Unity.UI;
using UnityEngine.UI;

scroll.SnapTo(row.transform);
scroll.SnapTo(row.transform, new Vector2(0f, 12f));
scroll.SnapXTo(row.transform, 8f);
scroll.SnapYTo(row.transform);

SnapTo keeps the current position on axes that are not enabled (horizontal / vertical). SnapXTo / SnapYTo only write that axis, and do nothing when it is not enabled.

Clone this wiki locally