here's the function i use for this, it is part of a library i made and use to ease a few things about canvas.
(这是我为此使用的功能,它是我创建的库的一部分,并用来简化画布的一些操作。)
I just put it on github in case other function might be be of use, i'll have to make a readme later...(我只是将其放在github上,以防其他功能可能有用,以后我将不得不自述...)
https://github.com/gamealchemist/CanvasLib
(https://github.com/gamealchemist/CanvasLib)
with namespaceing removed, the code is as follow to insert a 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;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…