Skip to content

Commit 1dc1f4a

Browse files
authored
Add a load progress example (#27543)
1 parent 86515c9 commit 1dc1f4a

File tree

1 file changed

+42
-6
lines changed

1 file changed

+42
-6
lines changed

aspnetcore/blazor/fundamentals/startup.md

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -205,14 +205,16 @@ document.documentElement.style.setProperty(
205205
'--blazor-load-percentage-text', `"${Math.floor(percentage)}%"`);
206206
```
207207

208-
The progress indicators are implemented in HTML in the `wwwroot/index.html` file:
208+
The default round progress indicator is implemented in HTML in the `wwwroot/index.html` file:
209209

210210
```html
211-
<svg class="loading-progress">
212-
<circle r="40%" cx="50%" cy="50%" />
213-
<circle r="40%" cx="50%" cy="50%" />
214-
</svg>
215-
<div class="loading-progress-text"></div>
211+
<div id="app">
212+
<svg class="loading-progress">
213+
<circle r="40%" cx="50%" cy="50%" />
214+
<circle r="40%" cx="50%" cy="50%" />
215+
</svg>
216+
<div class="loading-progress-text"></div>
217+
</div>
216218
```
217219

218220
To review the Blazor WebAssembly project template markup and styling for the default progress indicators, see the ASP.NET Core reference source:
@@ -222,6 +224,40 @@ To review the Blazor WebAssembly project template markup and styling for the def
222224

223225
[!INCLUDE[](~/includes/aspnetcore-repo-ref-source-links.md)]
224226

227+
Instead of using the default round progress indicator, the following example shows how to implement a linear progress indicator.
228+
229+
In `wwwroot/css/app.css`, a CSS variable is used to pass the value of `--blazor-load-percentage` to the `scale` property of a blue pseudo-element that indicates the loading progress of the app's files:
230+
231+
```css
232+
.linear-progress {
233+
background: silver;
234+
width: 50vw;
235+
margin: 20% auto;
236+
height: 1rem;
237+
border-radius: 10rem;
238+
overflow: hidden;
239+
position: relative;
240+
}
241+
242+
.linear-progress:after {
243+
content: '';
244+
position: absolute;
245+
inset: 0;
246+
background: blue;
247+
scale: var(--blazor-load-percentage, 0%) 100%;
248+
transform-origin: left top;
249+
transition: scale ease-out 0.5s;
250+
}
251+
```
252+
253+
As the app loads, `--blazor-load-percentage` is updated automatically, which dynamically changes the progress indicator's visual representation.
254+
255+
In `wwwroot/index.html`, remove the default SVG round indicator in `<div id="app">...</div>` and replace it with the following markup:
256+
257+
```html
258+
<div class="linear-progress"></div>
259+
```
260+
225261
## Additional resources
226262

227263
* [Environments: Set the app's environment](xref:blazor/fundamentals/environments)

0 commit comments

Comments
 (0)