Randomly generated floating/hovering animation in JS
All four of the circles below are using a different set of keyframes
Usage
createKeyframe('levitate', generateRandomDisplacements());
Output
@keyframes levitate {0% {transform:translateX(0px) translateY(0px);}5% {transform:translateX(-4px) translateY(6px);}....
You can use a css insertion library like this one to add this output to the <head>
of your html file.
CSS
.circle-1 {
animation: levitate 45s ease-in-out infinite;
}
@keyframes levitate {
0% {
transform: translateX(0px) translateY(0px);
}
5% {
transform:translateX(-4px) translateY(6px);
}
...
}
Change the const
options for different results.
For the gif above, I used the default options specified below.