Default value
If your website follows a normal flow and you have not limited the body or html height, you will not need to do anything to configure it, and the component will behave like the one you've probably already noticed on our website. If you put it at the layout level, it will run on all the pages of your site.
<MudScrollToTop> <MudFab Color="Color.Tertiary" StartIcon="@Icons.Material.Filled.ArrowCircleUp" /> </MudScrollToTop>
Setup
If the element you want to scroll is not the root element, you can specify it with the Selector
property. In this example, we are going to scroll in the container marked with the selector #unique_id_scroll_section
. Notice how the button that appears at the bottom right of this container changes its color when you scroll.
Scroll inside this container
Some initial long text
Middle text
Bottom text
<div id="unique_id_scroll_section" class="ma-0" style="height:300px;overflow: auto;"> <MudPaper Elevation="0" Height="3500px" Class="d-flex flex-column justify-space-between py-6"> <MudText Typo="Typo.h3" Align="Align.Center">Scroll inside this container</MudText> <MudText Typo="Typo.h3" Align="Align.Center">Some initial long text</MudText> <MudText Typo="Typo.h3" Align="Align.Center">Middle text</MudText> <MudText Typo="Typo.h3" Align="Align.Center">Bottom text</MudText> <MudScrollToTop TopOffset="100" OnScroll="OnScroll" Selector="#unique_id_scroll_section" VisibleCssClass="visible absolute" HiddenCssClass="invisible"> <MudButton Variant="Variant.Filled" StartIcon="@Icons.Material.Filled.ArrowUpward" Color="Color">Go to top</MudButton> </MudScrollToTop> </MudPaper> </div>
@code{ Color Color = Color.Success; private void OnScroll(ScrollEventArgs e) { Color = (e.FirstChildBoundingClientRect.Top*-1) switch { var x when x< 500 => Color.Primary, var x when x < 1500 => Color.Secondary, var x when x < 2500 => Color.Tertiary, _=>Color.Error }; } }