下面的有用链接除了显示使用双缓冲的示例和优点之外,还显示了使用html5
canvas元素的其他一些性能提示。它包含指向jsPerf测试的链接,这些链接将跨浏览器的测试结果汇总到Browserscope数据库中。这样可以确保性能提示得到验证。
为了方便起见,我提供了本文所述的有效双缓冲的最小示例。
// canvas element in DOMvar canvas1 = document.getElementById('canvas1');var context1 = canvas1.getContext('2d');// buffer canvasvar canvas2 = document.createElement('canvas');canvas2.width = 150;canvas2.height = 150;var context2 = canvas2.getContext('2d');// create something on the canvascontext2.beginPath();context2.moveTo(10,10);context2.lineTo(10,30);context2.stroke();//render the buffered canvas onto the original canvas elementcontext1.drawImage(canvas2, 0, 0);


