我试图在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)
我只希望它来回旋转,而不必在每个步骤的变换中应用这些属性。这里只使用了两个步骤(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);
}
}
这甚至可能吗?
附言。我不是在寻找将width
/更改height
为scale
和/或将margin
/top
属性更改为的答案translate
。LESS/SASS 也没有任何东西可以使值易于更改,因为它仍然会导致重复的代码。