@page "/" <h1>Flash Animation</h1> <table class="table table-striped"> <thead><tr><th>Name</th><th>Value</th></tr></thead> <tbody> @foreach(var s in sensors) { <tr class="@s.Css"> <td>@s.Name</td><td>@s.Value</td> </tr> } </tbody> </table> <hr/> @* fake an event updating a sensor *@ <button @onclick="FakeEvent">Fake Event</button> <p>@message</p> @code { const int count = 5; Random rand = new Random(); string message; List<Sensor> sensors = new List<Sensor>(); // create a list of sensors at start protected override void OnInitialized() { for(var i=0; i<count;i++) { sensors.Add(new Sensor(i)); } message = $"Created {count} sensors"; } void FakeEvent() { // pick a random sensor int index = rand.Next(0, count); // update this sensor sensors[index].Update(); message = $"Sensor {index} updated"; } public class Sensor { public Sensor(int number){ Name = $"Sensor {number}"; Value =1; } public string Name { get;set;} public int Value {get;set;} public string Css { get;set; } public void Update() { Value +=1; // sensor value changes // swap the CSS round, this triggers the animation // the two classes could be the same colour but I used a different // colour to make it clearer Css = Css == "new-item1" ? "new-item2" : "new-item1"; } } }
namespace BlazorFiddleProject { using Microsoft.AspNetCore.Components.Builder; using Microsoft.Extensions.DependencyInjection; public class Startup { public void ConfigureServices(IServiceCollection services) { } public void Configure(IComponentsApplicationBuilder app) { app.AddComponent<App>("app"); } } }
<!DOCTYPE html> <html> <head> <meta charset="utf-8"/> <meta name="viewport" content="width=device-width"> <title>BlazorFiddleProject</title> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"> <script src="_content/MatBlazor/dist/matBlazor.js"></script> <style> app { } /* flash v1 */ .new-item1 { -webkit-animation: flash 3s; /* Safari 4.0 - 8.0 */ -webkit-animation-iteration-count: 1; /* Safari 4.0 - 8.0 */ } /* flash v2 */ .new-item2 { -webkit-animation: flash 3s; /* Safari 4.0 - 8.0 */ -webkit-animation-iteration-count: 1; /* Safari 4.0 - 8.0 */ } @-webkit-keyframes flash { 0% { background-color: white; color: red } 5% { background-color: yellow; } 90% { background-color: white; } 100% { background-color: white; color: black; } } @keyframes flash { 0% { background-color: white; color: red } 5% { background-color: yellow; } 90% { background-color: white; } 100% { background-color: white; color: black; } } </style> <script type="text/javascript"> </script> </head> <body> <app>Loading...</app> <script src="_framework/blazor.webassembly.js"></script> <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script> </body> </html>

Add component

BlazorFiddle was updated from Blazor 0.7 to .NET 6.0. Your old source code could not work. You need to upgrade to latest.