performance:性能
layers: 圖層
recalculate style: 從新計算樣式
paint:重繪
layout:迴流
update layer tree: 更新圖層樹
composite layers: 合併圖層html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <style> #box { position: relative; top: 0; transform: translateY(0); width: 100px; height: 100px; background-color: red; } </style> </head> <body> <div id="box"></div> <script> setTimeout(() => { document.querySelector('#box').style.top = '100px'; }, 2000) </script> </body> </html>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <style> #box { transform: translateY(0); width: 100px; height: 100px; background-color: red; } </style> </head> <body> <div id="box"></div> <script> setTimeout(() => { document.querySelector('#box').style.transform = 'translateY(100px)'; }, 2000) </script> </body> </html>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <style> #box { width: 100px; height: 100px; background-color: red; } </style> </head> <body> <div id="box"></div> <script> setTimeout(() => { document.querySelector('#box').style.visibility = 'hidden'; }, 2000) </script> </body> </html>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <style> #box { width: 100px; height: 100px; background-color: red; opacity: 1; transform: translateZ(0) } </style> </head> <body> <div id="box"></div> <script> setTimeout(() => { document.querySelector('#box').style.opacity = '0'; }, 2000) </script> </body> </html>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <style> #box { position: relative; will-change: transform; width: 100px; height: 100px; background-color: red; opacity: 1; } </style> </head> <body> <div id="box"></div> <script> setTimeout(() => { document.querySelector('#box').style.opacity = '0'; document.querySelector('#box').style.width = '300px'; document.querySelector('#box').style.height = '300px'; document.querySelector('#box').style.left = '300px'; document.querySelector('#box').style.top = '200px'; document.querySelector('#box').style.opacity = '0'; }, 2000) </script> </body> </html>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <style> #box { position: relative; will-change: transform; width: 100px; height: 100px; background-color: red; opacity: 1; } #box.action { width: 200px; height: 300px; left: 300px; top: 200px; } </style> </head> <body> <div id="box"></div> <script> setTimeout(() => { document.querySelector('#box').className = "action"; }, 2000) </script> </body> </html>