1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <style> .div { width: 100px; height: 100px; background: pink; margin: 0 auto; animation: fadenum ease-in 1s; animation-fill-mode: forwards; position: absolute; will-change: left; // 开启GPU加速 left: 20px; top: 220px; }
@keyframes fadenum { 0% { /* left: 0px; */ transform: translateX(0); // 浏览器开启GPU加速 } 100% { /* left: 140px; */ transform: translateX(140px); } } </style>
<div class="div"></div> </body> </html>
|
未开启GPU加速时,渲染层和div在一层


开启GPU加速后,可以看到分层渲染

参考:https://www.douyin.com/video/7298924329268546866