と組み合わせて使用する場合、 DRY CSS コードを実現しようとしています。私が次のものを持っているとしましょう:transform
keyframes
HTML
<div id="box"></div>
CSS
#box {
width:300px;
height:300px;
background-color:red;
animation: animate 5s;
animation-iteration-count: infinite;
animation-direction: alternate;
animation-timing-function: ease-in-out;
}
@keyframes animate {
from {
transform: scale(0.8) translateY(100px) rotate(10deg);
}
to {
transform: scale(0.8) translateY(100px) rotate(-10deg);
}
}
アニメーション内でscale(0.8)
andを実行しないようにするにはどうすればよいですか? translateY(100px)
各ステップの変換内でこれらのプロパティを適用することなく、前後に回転させたいだけです。ここでは、2 つのステップ (および) のみが使用されてfrom
いますが、複数のステップが使用されてto
いる場合 (たとえば0%
、ご想像のとおり、変更が後で表示される場合、これはあまり良くありません。20%
40%
60%
80%
100%
transform
最終的に、私はこのようなものを探しています (プロパティがオーバーライドされるため、これは不可能です):
#box {
transform: scale(0.8) translateY(100px);
}
@keyframes animate {
from {
transform: rotate(10deg);
}
to {
transform: rotate(-10deg);
}
}
これは可能ですか?
Ps。width
/height
を にscale
変更したり、margin
/top
プロパティを に変更したりする答えを探しているわけではありませんtranslate
。また、値を簡単に変更できるようにするための LESS/SASS はありません。コードの重複が発生するためです。