防止调整窗口大小时清除画布。
防止调整窗口大小时清除画布。
我试图创建一个简单的应用程序,该应用程序在Canvas标签内绘制矩形。我已经成功将Canvas调整为全屏,但是每当我调整视口大小时,Canvas会被清除。我想阻止它清除并保留其中的内容。有什么建议吗?
这是用于应用程序的主要类。是Alvin Crespo。
var app = (function() {
var domBod = document.body;
var canvas = null;
var canvasWidth = null;
var canvasHeight = null;
return {
initApplication: function() {
canvas = document.getElementById('canvas') || null;
this.windowResized();
if (canvas) {
canvasWidth = canvas.offsetWidth;
canvasHeight = canvas.offsetHeight;
}
window.onresize = this.windowResized;
circles.canvas = canvas;
circles.canvasWidth = canvasWidth;
circles.canvasHeight = canvasHeight;
circles.generateCircles(10);
setInterval(function() {
circles.animateCircles();
}, 50);
},
windowResized: function() {
(this.domBod === null) ? 'true' : 'false';
try {
console.log(canvas);
canvas.setAttribute('width', document.body.clientWidth);
canvas.setAttribute('height', document.body.clientHeight);
} catch (e) {
console.log(e.name + " :: " + e.message);
}
},
getCanvas: function() {
return canvas;
}
};
})();