简体   繁体   English

CSS关键帧动画缓慢/波动

[英]CSS keyframe animations laggy/choppy

I have a problem with my animations. 我的动画有问题。 I am writing a chat which consists of a header, a body (where the dialog is) and an input field. 我正在写一个由标题,正文(对话框所在的地方)和输入字段组成的聊天。 It is positioned as so: 它的位置如下:

.chatWindowContainer {
    display: flex;
    flex-flow: column;
    position: absolute;
    bottom: 0px;
    right: 15%;
    margin-left: 10px;
    background-color: white;
    width: 350px;
    box-shadow: 0 20px 20px 5px rgba(0, 0, 0, 0.2),
    0 0px 10px 0 rgba(0, 0, 0, 0.19);
}

When clicking on the header I want to minimize the body and inputfield such that the header is the only thing that is visible (pretty much exactly like the facebook chat). 当单击标题时,我要最小化正文和输入字段,以使标题是唯一可见的内容(与Facebook聊天非常相似)。

It is working ok but my problem is that the animation is not smooth at all. 一切正常,但我的问题是动画根本不流畅。 I have tried the translateZ(0) trick but that only seems to work for transitions and not animations. 我尝试了translateZ(0)技巧,但这似乎仅适用于过渡效果,而不适用于动画效果。

Does anyone have a solution for this? 有人对此有解决方案吗?

My animations are very simple and looks like this: 我的动画非常简单,看起来像这样:

@keyframes minimize {
0% {
    max-height: 400px;
}
100% {
    max-height: 0px;
    padding: 0;
    margin: 0;
    }
}

@keyframes minimizeInputBox {
    0% {
        max-height: 40px;
    }
    100% {
        max-height: 0px;
        padding: 0;
        margin: 0;
    }
}
@keyframes minimizeChildren {
    0% {
        max-height: 400px;
        opacity: 0;
    }
    100% {
        opacity: 0;
        max-height: 0px;
        padding: 0;
        margin: 0;
        font-size: 0px;
    }
}

I also have maximize functions and those are exactly the same but vice versa. 我也具有最大化功能,这些功能完全相同,反之亦然。

Any help would be appreciated! 任何帮助,将不胜感激!

You are animating max-height which causes a reflow in layout which is quire GPU intensive. 您正在为max-height设置动画,这会导致需要GPU密集型布局的回流。 See https://csstriggers.com/ for CSS properties which cause layout, paint or composite calculations. 请参阅https://csstriggers.com/了解CSS属性,这些属性会导致布局,绘制或复合计算。 The most performant way would be to do this in JavaScript to calculate the boundaries upfront and use transform along with requestAnimationFrame to manipulate the dimensions. 最有效的方法是在JavaScript中执行此操作以预先计算边界,并使用transformrequestAnimationFrame来操纵尺寸。 But I have to admit it is a little tricky. 但是我不得不承认这有点棘手。 Paul Lewis has a lot of good material about the FLIP technique: https://aerotwist.com/blog/flip-your-animations/ 保罗·刘易斯(Paul Lewis)有很多有关FLIP技术的好材料: https : //aerotwist.com/blog/flip-your-animations/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM