css - 向 css will-change 添加几个属性

标签 css

我在我的CSS中使用will-change:transform来加速元素动画,我想知道是否有一种方法可以添加多个属性,即具有变换和不透明度。

最佳答案

根据MDNW3C可以使用逗号:

.element {
  will-change: transform, opacity;
}

您可能已经意识到这一点,但为了完整起见:

Don’t Spam will-change Across Too Many Properties or Elements

A common initial response to seeing will-change is to assume that code like this is a good idea:

* { will-change: transform, opacity /* , ... */; }

After all, this tells the browser to go ahead and optimize everything, which has to be good right?

Wrong. The browser already tries as hard as it can to optimize everything. Telling it to do so explicitly doesn’t help anything, and in fact has the capacity to do a lot of harm; some of the stronger optimizations that are likely to be tied to will-change end up using a lot of a machine’s resources, and when overused like this can cause the page to slow down or even crash. [W3C]

关于css - 向 css will-change 添加几个属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41299063/

相关文章:

CSS div 宽度 50% 在 IE 中不起作用

javascript - 使用全高内容

JavaScript if 语句不应该返回 true

javascript - Bootstrap Modal 隐藏滚动条

html - href 链接内跨度上的不同颜色

javascript - 不要重复上次使用的图像

jquery - 使用 css 和 jquery 的语音气泡工具提示

html - 如何在 HTML 中使表中的 <tr> 透明?

jquery - 如何仅更改选定的元素 css

php - 在服务器上将带有 css 的动态 php 页面的内容保存为 pdf