All of my canvas drawing functions start something like this:
function drawMe(){
var canvas = document.getElementById('canvas-id');
var ctx = null;
ctx = canvas.getContext('2d');
...
}
However I now want to draw the same image on a (variable) number of canvases, is there some alternative to getElementById() (perhaps in jQuery?) which can be used to easily grab more than one at once?
Thanks!
Josh
drawing to multiple canvases will be extremely inefficient, because rendering is one of most expensive operations you can do.
what you want to do is to use buffer. you can simply draw from one canvas to another.
here’s a fiddle.
remember, you only need to call
ctx.drawImageonce – after you’re done with all drawing on first canvas.