CSS Animation on Element Creation

by mithril

Level: beginner • Mithril.js Version: latest

A simple example animating an element via CSS when the element is created. This is straight-forward by just adding an CSS animation to a class normally. There is no need for specific Mithril.js code. This example was taken from the official website at https://mithril.js.org/animation.html#animation-on-element-creation and slightly modified.

Live Example

Dependencies

Type Name URL
scriptmithril@latesthttps://unpkg.com/mithril@latest

Styles

.fancy {
  animation:fade-in 2.0s;
  font-size: 2rem;
}
@keyframes fade-in
{
  from {opacity:0;}
  to {opacity:1;}
}

JavaScript

const FancyComponent = {
    view: function() {
        return m(".fancy", "Hello world")
    }
}

m.mount(document.body, FancyComponent)

The snippet is using the most current version of Mithril.js framework. It is aimed at beginners and shows some basic recipes.

In addition to the Mithril.js hyperscript function m(), here we can see an example of Mithril.js' m.mount API method.

The example was contributed by mithril and last modified on 19 October 2021. Click here to see more examples contributed by the author.

Contribute

If anyone has some improvements, that should be addressed, let me know by opening an issue. Or simply fork the repository on GitHub, push your commits and send a pull request. For starting your work, you can click the edit link below. Thanks for contributing.

See more code examples  •  Edit this example on GitHub