docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Scroll in a ScrollView

    To simulate a scroll, use the ScrollWheel() method from the PanelSimulator class.

    The following example shows how to simulate scrolling inside a ScrollView:

    [Test]
    public void ScrollExample()
    {
        // Make sure the UI is totally up to date.
        simulate.FrameUpdate();
    
        // Fetch the scrollView.
        var scrollView = rootVisualElement.Q<ScrollView>("MyScrollView");
    
        var scrollViewStateBefore = scrollView.scrollOffset;
    
        // Send events to scroll the mouse wheel.
        simulate.ScrollWheel(new Vector2(0, 0.5f),
            rootVisualElement.worldBound.center);
        simulate.FrameUpdate();
    
        Assert.That(scrollView.scrollOffset, Is.Not.EqualTo(scrollViewStateBefore));
    }
    

    Additional resources

    • Move the mouse to a visual element
    In This Article
    Back to top
    Copyright © 2025 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)