Reputation: 33
I'm very new to Canvas animations, and I'm stuck on something and wondering if you guys could help me out.
I'm using this demo - http://cssdeck.com/labs/html5-canvas-particles-web-matrix - but I need it to recalculate the canvas size when the window is resized. This needs to be updated in the jQuery, not the CSS or HTML (FYI, CSS is canvas width & height = 100%).
Can anyone help me out?
Thanks! :)
Upvotes: 1
Views: 2230
Reputation: 1773
Your event window.onresize
should not declare new variables H
and W
but use 'old' ones instead, like this:
window.onresize = function() {
W = window.innerWidth;
H = window.innerHeight;
canvas.width = W;
canvas.height = H;
}
If you want to modify other parameters like particleCount
or particles
array also don't use var
, because it will create new variables in function scope.
Upvotes: 3