Skip to content

Instantly share code, notes, and snippets.

@Haraldson
Last active August 29, 2015 13:56
Show Gist options
  • Save Haraldson/8869035 to your computer and use it in GitHub Desktop.
Save Haraldson/8869035 to your computer and use it in GitHub Desktop.

Fade in dynamically created elements using CSS3 animations

A simple proof of concept where CSS3 animations with animation-fill-mode: forwards is used to fade in elements created and added to DOM with JavaScript.

$(function()
{
var $dynamicallyCreatedElement = $('<p class="dynamically-created-element">This will fade in!</p>');
$('body').append($dynamicallyCreatedElement);
});
@keyframes fade-in {
0% { opacity: 0; }
100% { opacity: 1; }
}
.dynamically-created-element {
opacity: 0;
animation-name: fade-in;
animation-duration: .5s;
animation-timing-function: ease-in-out;
animation-iteration-count: 1;
animation-fill-mode: forwards;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment