user11643 user11643 - 5 months ago 24
HTML Question

Resize canvas on page load

I am using the following snippet to resize a canvas element successfully. I need it to resize a canvas element on page load and not require user interaction to fire the

windowResize()
function.

(function($){
$(window).resize(function(){
windowResize();
});
})(jQuery);

function windowResize(){
stage.canvas.width = window.innerWidth;
stage.canvas.height = window.innerHeight;
var test = (window.innerHeight/500)*1;
exportRoot.scaleX = exportRoot.scaleY = test;
}

K3N K3N
Answer

Just modify your snippet to:

$(window).on('resize load', windowResize);

This will invoke windowResize() at both load and resize.

Comments