CSS动画转换转换也更改了Translatex,但在动画中未指定
在这里,我有一个简单的CSS文件,其中包含2个动画。
.div
transform: translateX(-50%);
}
.fade-in {
animation-name: fade-in;
animation-duration: .2s;
}
.fade-out {
animation-name: fade-out;
animation-duration: .2s;
}
@keyframes fade-out {
0% {
opacity: 100%;
}
100% {
opacity: 0%;
transform: translateY(-10px);
}
}
@keyframes fade-in {
0% {
opacity: 50%;
transform: translateY(-10px);
}
100% {
opacity: 100%;
}
}
为什么我只在动画键框中指定了翻译,它也会操纵转换属性中的Translatex?我该如何做到这一点,以便它只会改变y值?
Here, I have a simple CSS file containing 2 animations.
.div
transform: translateX(-50%);
}
.fade-in {
animation-name: fade-in;
animation-duration: .2s;
}
.fade-out {
animation-name: fade-out;
animation-duration: .2s;
}
@keyframes fade-out {
0% {
opacity: 100%;
}
100% {
opacity: 0%;
transform: translateY(-10px);
}
}
@keyframes fade-in {
0% {
opacity: 50%;
transform: translateY(-10px);
}
100% {
opacity: 100%;
}
}
Why is it that even though I only specified translateY in the animation keyframes, it also manipulates the translateX in the transform property? And how can I make it so it only changes the Y value?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您正在覆盖
变换
peropty。 Merge转换:Translatex(-50%)
和变换:translatey(-10px);
by do:transform:transform:transforate:-50%,-10px);
执行此操作:
You are overriding the
transform
peropty. Mergetransform: translateX(-50%)
andtransform: translateY(-10px);
by doing:transform: translate(-50%, -10px);
Do this:
您覆盖整个
transform
属性 - 不仅仅是翻译。如果要保留translatex
值,则必须将其包含在动画中。You override whole
transform
attribute - not just translate. If you want to keep yourtranslateX
value you have to include it in animation too.