關鍵英文詞: layout paint compositecss
管道,恩, 跟linux上的概念很像,上一個處理完了交給下一個linux
JS/CSS -> layout -> paint -> compositeweb
改變元素寬高佈局屬性的,都會引發layout,從而有後面的管道性能優化
JS/css -> paint -> composite佈局
只改變元素的顏色、陰影什麼的性能
JS/css -> composite優化
目前只引發合成層渲染的CSS屬性: transform
& opacity
動畫
特殊使用,提高到其本身的層,建合成器層:google
will-change: transform;
transform: translateZ(0);
複製代碼
合成器線程能夠單獨處理用戶的交互並使內容更變,不需求主線程去執行,主線程執行js、佈局、樣式、繪製。spa
ele.getBoundingClientRect()
確保回調在下一幀開始時運行,確保當前樣式已渲染OK
requestAnimationFrame(function () {
el.classList.add('animate-to-transform')
el.style.transform = ''
})
複製代碼
developers.google.com/web/fundame… developers.google.com/web/fundame… developers.google.com/web/fundame…