SMILET
除了显示使用双缓冲的示例和优点之外,以下有用链接还显示了使用html5 canvas元素的其他几个性能提示。它包含指向jsPerf测试的链接,这些测试将跨浏览器的测试结果聚合到Browserscope数据库中。这可确保验证性能提示。http://www.html5rocks.com/en/tutorials/canvas/performance/为方便起见,我已经包含了文章中描述的有效双缓冲的最小示例。// 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);