GithubHelp home page GithubHelp logo

nventimiglia / blazor.transitions Goto Github PK

View Code? Open in Web Editor NEW
12.0 3.0 1.0 735 KB

Blazor Transition Example

License: MIT License

HTML 47.58% C# 4.62% CSS 30.72% JavaScript 17.07%
blazor blazor-webassembly blazor-extensions blazor-component aspnet-core aspnetcore animation-css

blazor.transitions's Introduction

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

@page "/counter"
@using BlazorApp1.Shared;

<Transition IsVisible="@IsVisible">
    <h1>Counter</h1>

    <p>Current count: @currentCount</p>

    <button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
</Transition>

<button class="btn btn-danger" @onclick="ShowHide">Toggle</button>

@code {
    private int currentCount = 0;

    public bool IsVisible { get; set; } = true;

    private void IncrementCount()
    {
        currentCount++;
    }

    private void ShowHide()
    {
        IsVisible = !IsVisible;
    }
}
<Transition IsVisible="forecasts.Length == 0" Class="fast">
    <p><em>Loading...</em></p>
</Transition>
<Transition IsVisible="forecasts.Length > 0" Class="delay-500ms">
    <table class="table animateList">
        <thead>
            <tr>
                <th>Date</th>
                <th>Temp. (C)</th>
                <th>Temp. (F)</th>
                <th>Summary</th>
            </tr>
        </thead>
        <tbody>
            @foreach (var forecast in forecasts)
            {
                <tr>
                    <td>@forecast.Date.ToShortDateString()</td>
                    <td>@forecast.TemperatureC</td>
                    <td>@forecast.TemperatureF</td>
                    <td>@forecast.Summary</td>
                </tr>
            }
        </tbody>
    </table>
</Transition>

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

<html>

<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <title>Blazor.Transitions.Example</title>
    <base href="/" />
    <link href="css/bootstrap/bootstrap.min.css" rel="stylesheet" />
    <link href="css/app.css" rel="stylesheet" />
    <link href="Blazor.Transitions.Example.styles.css" rel="stylesheet" />
    <link href="manifest.json" rel="manifest" />
    <link rel="apple-touch-icon" sizes="512x512" href="icon-512.png" />

    <link href="css/animate.css/animate.min.css" rel="stylesheet" />
    <link href="css/transitions/transitions.css" rel="stylesheet" />
</head>

<body>
    <div id="app">Loading...</div>

    <div id="blazor-error-ui">
        An unhandled error has occurred.
        <a href="" class="reload">Reload</a>
        <a class="dismiss">๐Ÿ—™</a>
    </div>
    <script src="_framework/blazor.webassembly.js"></script>
    <script>navigator.serviceWorker.register('service-worker.js');</script>
    <script src="css/transitions/transitions.js"></script>

</body>

</html>

blazor.transitions's People

Contributors

nventimiglia avatar zutron avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

zutron

blazor.transitions's Issues

Rather cryptic VSCoreDebugProtocol.ProtocolException when running example code

Hi there,

Very interested to get this working on my .NET 5.0 Blazor web assembly project but after implementing it doesnt work as expected. Everything compiles fine, I don't get any runtime errors, but I just have no animations.

When trying to run your example project I just get a VSCoreDebugProtocol.ProtocolException and the code refuses to run. I've not had much luck tracing the cause of the problem.

Are you using this code in production? Have you tried it against .NET 5?

I originally used the Blazor.Animate library, but that one doesn't have the ability to programmatically hide/fade animations, only show/fadein.

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.