css animation code code example
Example 1: css animation
<style>
.my-element {
width: 100%;
height: 100%;
animation: tween-color 5s infinite;
}
@keyframes tween-color {
0% {
background-color: red;
}
50% {
background-color: green;
}
100% {
background-color: red;
}
}
html,
body {
height: 100%;
}
<style>
<body>
<div class="my-element"></div>
</body>
Example 2: animation in css
@keyframes example {
from {
color: #a8dadcff;
}
to {
color: #e63946ff;
}
}
.animation {
animation-name: "example";
animation-duration: 4s;
animation-iteration-count: infinite;
animation-timing-function: ease-in-out;
}
Example 3: css animation
CSS animation properties template:
{
animation-name: anima-name;
animation-duration: 1s;
animation-iteration-count: infinite;
animation-delay: 2s;
animation-direction: reverse | normal | alternate | alternate-reverse ;
animation-timing-function: ease | ease-out | ease-in | ease-in-out | linear | cubic-bezier(x1, y1, x2, y2) (e.g. cubic-bezier(0.5, 0.2, 0.3, 1.0));
animation-fill-mode:forwards | backwards | both | none;
}
@keyframes anima-name {
from {
background-position:right;
}
to {
background-position:left;
}
}
@keyframes anima-name {
0% {
background-color: red;
}
50% {
background-color: green;
}
100% {
background-color: red;
}
}
Example 4: adding animation to images css
basic animation drop
//drop is variable named for the animation
@keyframes drop {
0% {
opacity: 0;
transform: translateY(-80px);
}
100% {
opacity: 1;
transform: translateY(0px);
}
}
img {
animation: drop 500ms ease;
}
Example 5: css animation
div{
animation: name duration timing-function delay iteration-count
direction fill-mode;
}
Example 6: Css animations
Here a codePen with cool animations:
https://codepen.io/DevLorenzo/pen/ExgpvJM