I put together two options for you- jsFiddle
Option 1- Not DRY but a little more condensed:
#box {
width:300px;
height:300px;
background:red;
animation: animate 1s ease-in-out 0s infinite alternate;
}
@keyframes animate {
from {
transform: scale(0.8) translateY(100px) rotate(10deg);
}
to {
transform: scale(0.8) translateY(100px) rotate(-10deg);
}
}
Option 2- Technically DRY, but not necessarily "better"
<div id="option2">
<div id="box2"></div>
</div>
#option2{
transform: scale(0.8) translateY(100px);
}
#box2 {
width:300px;
height:300px;
background-color:blue;
animation: animate2 6s ease-in-out 0s infinite alternate;
}
@keyframes animate2 {
0%, 40%, 80% {
transform: rotate(10deg);
}
20%, 60%, 100% {
transform: rotate(-10deg);
}
}
I would guess that using Option 2 may be worth it, if you're using a much more complex animation, but I'm not sure if just wrapping it in a containing div
and scaling / translating the containing div
would offer any real benefit on a small scale.