CSS的性能相对于translateZ(0)(CSS performance relative to translateZ(0))

编程入门 行业动态 更新时间:2024-10-22 18:28:15
CSS的性能相对于translateZ(0)(CSS performance relative to translateZ(0))

许多博客已经表现出“欺骗”GPU的性能增益,认为一个元素是3D,通过使用transform: translateZ(0)来加快动画和转换。 我想知道如何以下列方式应用这种变换的含义是什么?

* {
    -webkit-transform: translateZ(0);
    -moz-transform: translateZ(0);
    -ms-transform: translateZ(0);
    -o-transform: translateZ(0);
    transform: translateZ(0);
}

A number of blogs have expressed the performance gain in 'tricking' the GPU to think that an element is 3D by using transform: translateZ(0) to speed up animations and transitions. I was wondering if there are implications to using this transform in the following manner:

* {
    -webkit-transform: translateZ(0);
    -moz-transform: translateZ(0);
    -ms-transform: translateZ(0);
    -o-transform: translateZ(0);
    transform: translateZ(0);
}

                

最满意答案

CSS转换创建一个新的堆栈上下文并包含块,如规范中所述。 在简单的英语中,这意味着应用于它们的变换的固定位置元素将更像是绝对定位的元素,并且z-index值可能会被扭曲。

如果你看这个演示 ,你会看到我的意思。 第二个div具有应用于其的变换,意味着它创建了一个新的堆叠上下文,并且伪元素堆叠在顶部而不是下面。

所以基本上不要这样做 仅在需要优化时应用3D转换。 -webkit-font-smoothing: antialiased; 是另一种利用3D加速而不产生这些问题的方法,但它只适用于Safari。

CSS transformations create a new stacking context and containing block, as described in the spec. In plain English, this means that fixed position elements with a transformation applied to them will act more like absolutely positioned elements, and z-index values are likely to get screwed with.

If you take a look at this demo, you'll see what I mean. The second div has a transformation applied to it, meaning that it creates a new stacking context, and the pseudo elements are stacked on top rather than below.

So basically, don't do that. Apply a 3D transformation only when you need the optimization. -webkit-font-smoothing: antialiased; is another way to tap into 3D acceleration without creating these problems, but it only works in Safari.

更多推荐

本文发布于:2023-08-06 16:14:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1451196.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:相对于   性能   CSS   relative   performance

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!