これは、私が作成したライブラリの一部であり、キャンバスに関するいくつかのことを容易にするために使用します。他の機能が役立つ可能性がある場合に備えて、githubに置いただけです。後でreadmeを作成する必要があります...
https://github.com/gamealchemist/CanvasLib
名前空間を削除すると、canvas を挿入するコードは次のようになります。
// insert a canvas on top of the current document.
// If width, height are not provided, use all document width / height
// width / height unit is Css pixel.
// returns the canvas.
insertMainCanvas = function insertMainCanvas (_w,_h) {
if (_w==undefined) { _w = document.documentElement.clientWidth & (~3) ; }
if (_h==undefined) { _h = document.documentElement.clientHeight & (~3) ; }
var mainCanvas = ga.CanvasLib.createCanvas(_w,_h);
if ( !document.body ) {
var aNewBodyElement = document.createElement("body");
document.body = aNewBodyElement;
};
document.body.appendChild(mainCanvas);
return mainCanvas;
}