Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
-2
rated 0 times [  3] [ 5]  / answers: 1 / hits: 28603  / 13 Years ago, fri, april 1, 2011, 12:00:00

I'm trying to create a simple app that draws rectangles within the Canvas tag. I've got the Canvas resizing to fullscreen, but whenever I resize the viewport, Canvas clears. I'm trying to prevent it from clearing and just keeping the content that's within it. Any ideas?


http://mediajux.com/experiments/canvas/drawing/


  /*
* This is the primary class used for the application
* @author Alvin Crespo
*/
var app = (function(){

var domBod = document.body;
var canvas = null;
var canvasWidth = null;
var canvasHeight = null;

return {

//Runs after the DOM has achieved an onreadystatechange of "complete"
initApplication: function()
{
//setup envrionment variables
canvas = document.getElementById('canvas') || null;

//we need to resize the canvas at the start of the app to be the full window
this.windowResized();

//only set the canvas height and width if it is not false/null
if(canvas)
{
canvasWidth = canvas.offsetWidth;
canvasHeight = canvas.offsetHeight;
}

//add window events
window.onresize = this.windowResized;

circles.canvas = canvas;
circles.canvasWidth = canvasWidth;
circles.canvasHeight = canvasHeight;
circles.generateCircles(10);

setInterval(function(){
circles.animateCircles();
}, 50);
},

/**
* Executes Resizing procedures on the canvas element
*/
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);
}
},

/**
* Returns the canvas element
* @returns canvas
*/
getCanvas: function()
{
return canvas;
}

};
})();

More From » html

 Answers
20

I believe you have implement a listener for screen resize and redraw the canvas content when that listener fires.


[#92959] Thursday, March 31, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
janettejordynm

Total Points: 550
Total Questions: 94
Total Answers: 98

Location: Senegal
Member since Fri, Aug 21, 2020
4 Years ago
janettejordynm questions
Tue, Nov 24, 20, 00:00, 4 Years ago
Sat, May 23, 20, 00:00, 4 Years ago
Mon, Apr 6, 20, 00:00, 4 Years ago
Tue, Feb 18, 20, 00:00, 4 Years ago
;