Aligning Spinner to the middle
5 Replies
IS
Indrajith Srinivasan
Syncfusion Team
November 24, 2021 08:12 AM UTC
Hi Belle,
Greetings from Syncfusion support,
We have validated your reported query. The SfSpinner will be positioned, to the center of the target element where is it placed. We have prepared a sample for your reference, placing the SfSpinner in the MainLayout page which show to the center of the page.
Code Snippet:
MainLayout.razor:
|
<CascadingValue Value="@this">
<div class="sidebar">
<NavMenu />
</div>
<div class="main">
<div class="top-row px-4">
<a rel='nofollow' rel='nofollow' href=https://docs.microsoft.com/aspnet/ target="_blank">About</a>
</div>
<div class="content px-4">
@Body
</div>
<SfSpinner @bind-Visible="@SpinnerVisible" CssClass="e-spin-overlay">
</SfSpinner>
</div>
</CascadingValue>
@code{
public bool SpinnerVisible { get; set; } = false;
public async Task ClickHandler()
{
this.SpinnerVisible = true;
StateHasChanged();
await Task.Delay(2000);
this.SpinnerVisible = false;
StateHasChanged();
}
} |
Index.razor
|
@using Syncfusion.Blazor.Buttons
<div>
<p>Click the button to show the spinner</p>
<SfButton @onclick="@ClickHandler">Show/Hide Spinner</SfButton>
</div>
@code{
[CascadingParameter]
public MainLayout mainLayoutObj { get; set; }
private async Task ClickHandler()
{
await mainLayoutObj.ClickHandler();
}
protected async override Task OnInitializedAsync()
{
await mainLayoutObj.ClickHandler();
}
} |
This ClickHandler method can be called anywhere from the page depends on the usage,
Note: Use `CascadingValue` in the MainLayout to access the main layout anywhere in the body.
Please let us know if the solution helps,
Regards,
Indrajith
BC
Belle Cruz
November 24, 2021 08:55 AM UTC
Thank you
My query is about how to align the loading spinner in the middle of page.
IS
Indrajith Srinivasan
Syncfusion Team
November 25, 2021 08:28 AM UTC
Hi Belle,
Good day to you,
You can align the spinner to the center of the target by setting the position as relative for the target element. Check the below code block example, of showing the spinner in the center of the target.
- In the below example, the spinner is shown in the center of the target(Same case is applicable, for the spinners rendered in the main page)
Code blocks:
|
@using Syncfusion.Blazor.Buttons
@using Syncfusion.Blazor.Spinner
<div>
<p>Click the button to show the spinner</p>
<SfButton @onclick="@ClickHandler">Show/Hide Spinner</SfButton>
<div id="SpinTarget" style="position: relative; height: 400px; border: 1px solid black">
<SfSpinner @bind-Visible="@SpinnerVisible" CssClass="e-spin-overlay">
</SfSpinner>
</div>
</div>
@code{
public bool SpinnerVisible { get; set; } = false;
public async Task ClickHandler()
{
SpinnerVisible = true;
this.StateHasChanged();
await Task.Delay(2000);
SpinnerVisible = false;
this.StateHasChanged();
}
}
|
If you are still facing any issues, can you please replicate the reported issue in the already shared sample and revert back to us ?
Regards,
Indrajith
BC
Belle Cruz
November 25, 2021 08:43 AM UTC
I want the loadin spinner in the middle of the page
IS
Indrajith Srinivasan
Syncfusion Team
November 26, 2021 06:38 AM UTC
Hi Belle,
You can center the spinner by setting the below CSS for the target element.
|
#spintarget {
left: 50%;
position: absolute;
text-align: center;
top: 50%;
} |
We have checked the shared screenshots, are you using SfSpinner in your page ?. If you are still facing any issues, can you please share the code blocks used or can you replicate the reported issue in the already shared sample and revert back to us ?
Regards,
Indrajith
SIGN IN To post a reply.
- 5 Replies
- 2 Participants
-
BC Belle Cruz
- Nov 23, 2021 10:25 AM UTC
- Nov 26, 2021 06:38 AM UTC