示例工程 50-performance
50-performance/demo-01-compositor/index.html
点击「运行示例」后,左侧显示源码、右侧显示运行结果;console 输出会实时回传。
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>合成友好动画</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<h1>合成友好动画</h1>
<p>同样位移,属性不同,浏览器做的事也不同。</p>
<div class="track">
<span class="label">transform</span>
<div class="box transform-box"></div>
</div>
<div class="track">
<span class="label">left</span>
<div class="box left-box"></div>
</div>
<pre><code>/* 好:只合成 */
@keyframes move {
to { transform: translateX(200px); }
}
/* 差:每帧布局 */
@keyframes move {
to { left: 200px; }
}</code></pre>
</body>
</html>