How to GPU accelerate CSS transform?

那年仲夏 提交于 2020-07-22 04:56:06

问题


I know that sometimes browsers will GPU accelerate a CSS transform. But when does that happen, and is there a way to force GPU acceleration for a smooth animation?

this article


回答1:


Most modern browsers support GPU acceleration, but they only use it when they think a DOM element will benefit from it. The strongest indication is that a 3D transformation is being applied. So use the 3D-equivalent transform. For example, instead of transform: translateX(50px), use transform: translate3d(50px, 0, 0). See this article for more information.




回答2:


You can use the css "will-change" property:

will-change: transform;

Some css properties which are GPU accelerated (not always):

  • filter
  • opacity
  • transform


来源:https://stackoverflow.com/questions/32614455/how-to-gpu-accelerate-css-transform

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!