项目作者: NVentimiglia

项目描述 :
Blazor Transition Example
高级语言: HTML
项目地址: git://github.com/NVentimiglia/Blazor.Transitions.git
创建时间: 2020-04-10T21:02:51Z
项目社区:https://github.com/NVentimiglia/Blazor.Transitions

开源协议:MIT License

下载


Blazor.Transitions

Blazor Transition Example

Experiment on how to handle intro/outro/update animations for Blazor components. Solution is a Blazor componenet with an IsVisible property. It listens to property changes and renders a div with an appropriate css class.

Supports 5 animations :

  • Intro (fade in)
  • Outro (fade out)
  • Update (yellow blink)
  • Intro Complete (snap to opacity 1)
  • Outro Complete (snap to opacity 0)

Uses this library for animation tweens
https://github.com/daneden/animate.css

Alt Text

  1. @page "/counter"
  2. @using BlazorApp1.Shared;
  3. <Transition IsVisible="@IsVisible">
  4. <h1>Counter</h1>
  5. <p>Current count: @currentCount</p>
  6. <button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
  7. </Transition>
  8. <button class="btn btn-danger" @onclick="ShowHide">Toggle</button>
  9. @code {
  10. private int currentCount = 0;
  11. public bool IsVisible { get; set; } = true;
  12. private void IncrementCount()
  13. {
  14. currentCount++;
  15. }
  16. private void ShowHide()
  17. {
  18. IsVisible = !IsVisible;
  19. }
  20. }
  1. <Transition IsVisible="forecasts.Length == 0" Class="fast">
  2. <p><em>Loading...</em></p>
  3. </Transition>
  4. <Transition IsVisible="forecasts.Length > 0" Class="delay-500ms">
  5. <table class="table animateList">
  6. <thead>
  7. <tr>
  8. <th>Date</th>
  9. <th>Temp. (C)</th>
  10. <th>Temp. (F)</th>
  11. <th>Summary</th>
  12. </tr>
  13. </thead>
  14. <tbody>
  15. @foreach (var forecast in forecasts)
  16. {
  17. <tr>
  18. <td>@forecast.Date.ToShortDateString()</td>
  19. <td>@forecast.TemperatureC</td>
  20. <td>@forecast.TemperatureF</td>
  21. <td>@forecast.Summary</td>
  22. </tr>
  23. }
  24. </tbody>
  25. </table>
  26. </Transition>

Don’t forget to copy the necessary files to /wwwroot/css and update index.html to link the js and css files.

  1. <html>
  2. <head>
  3. <meta charset="utf-8" />
  4. <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
  5. <title>Blazor.Transitions.Example</title>
  6. <base href="/" ></base>
  7. <link href="css/bootstrap/bootstrap.min.css" rel="stylesheet" />
  8. <link href="css/app.css" rel="stylesheet" />
  9. <link href="Blazor.Transitions.Example.styles.css" rel="stylesheet" />
  10. <link href="manifest.json" rel="manifest" />
  11. <link rel="apple-touch-icon" sizes="512x512" href="icon-512.png" />
  12. <link href="css/animate.css/animate.min.css" rel="stylesheet" />
  13. <link href="css/transitions/transitions.css" rel="stylesheet" />
  14. </head>
  15. <body>
  16. <div id="app">Loading...</div>
  17. <div id="blazor-error-ui">
  18. An unhandled error has occurred.
  19. <a href="" class="reload">Reload</a>
  20. <a class="dismiss">🗙</a>
  21. </div>
  22. <script src="_framework/blazor.webassembly.js"></script>
  23. <script>navigator.serviceWorker.register('service-worker.js');</script>
  24. <script src="css/transitions/transitions.js"></script>
  25. </body>
  26. </html>