CSS shake animation
by Konstantin Rouda
HTML
<div class="c-parent">
<div class="c-child">Hello</div>
</div>
CSS
HTML {
font-size: 100%;
line-height: 1.5;
box-sizing: border-box;
}
BODY {
/*using fluid typography (https://goo.gl/o9sRyq)*/
font-size: calc(20px + (30 - 20) * (100vw - 300px) / (700 - 300) );
margin: 0;
color: #3a3d40;
}
*, *::before, *::after {
box-sizing: inherit;
color: inherit;
}
.c-parent {
width: 10rem;
height: 5rem;
margin: 1rem auto 0;
border: 1px solid cornflowerblue;
border-radius: .11rem;
}
.c-child {
max-width: 50%;
height: 3rem;
margin: .1rem auto;
background: firebrick;
animation: shake 0.08s 0.1s infinite;
animation-play-state: paused;
}
.c-parent:hover .c-child {
animation-play-state: running;
}
@keyframes shake {
0% { transform: translateX(0); }
50% { transform: translateX(-1px); }
100% { transform: translateX(2px); }
}
JavaScript
/*
Example from:
https://youtu.be/hWni4GCiJ_s?t=12m17s
*/