交互
用于优化即将发生变化的元素的动画的工具。
Class | Styles |
---|---|
will-change-auto | will-change: auto; |
will-change-scroll | will-change: scroll-position; |
will-change-contents | will-change: contents; |
will-change-transform | will-change: transform; |
will-change-<custom-property> | will-change: var(<custom-property>); |
will-change-[<value>] | will-change: <value>; |
使用 will-change-scroll
、will-change-contents
和 will-change-transform
工具来优化预期在不久的将来会发生变化的元素,通过指示浏览器在实际开始动画之前准备必要的动画:
<div class="overflow-auto will-change-scroll"> <!-- ... --></div>
建议在元素发生变化之前应用这些工具,并在动画结束后不久使用 will-change-auto
将其移除。
will-change
属性旨在作为处理已知性能问题时的最后手段。避免过度使用这些工具,或者仅仅是为了预防性能问题,因为这实际上可能导致页面性能下降。
Use the will-change-[<value>]
syntax to set the will-change
属性 based on a completely custom value:
<div class="will-change-[top,left] ..."> <!-- ... --></div>
For CSS variables, you can also use the will-change-(<custom-property>)
syntax:
<div class="will-change-(--my-properties) ..."> <!-- ... --></div>
This is just a shorthand for will-change-[var(<custom-property>)]
that adds the var()
function for you automatically.